[2103] * kern/dl.c (grub_dl_load_file): Close file immediately when

"David S. Miller" <[email protected]>
Newsgroups gmane.comp.boot-loaders.grub.cvs
Message-ID <[email protected]>
Revision: 2103
          http://svn.sv.gnu.org/viewvc/?view=rev&root=grub&revision=2103
Author:   davem
Date:     2009-04-13 23:03:50 +0000 (Mon, 13 Apr 2009)
Log Message:
-----------
	* kern/dl.c (grub_dl_load_file): Close file immediately when
	we are done using it.

Modified Paths:
--------------
    trunk/grub2/ChangeLog
    trunk/grub2/kern/dl.c

Modified: trunk/grub2/ChangeLog
===================================================================
--- trunk/grub2/ChangeLog	2009-04-13 23:01:54 UTC (rev 2102)
+++ trunk/grub2/ChangeLog	2009-04-13 23:03:50 UTC (rev 2103)
@@ -49,6 +49,9 @@
 	* util/hostdisk.c (make_device_name): Do not make any assumptions
 	about the length of drive names.
 
+	* kern/dl.c (grub_dl_load_file): Close file immediately when
+	we are done using it.
+
 2009-04-12  David S. Miller  <[email protected]>
 
 	* kern/misc.c (grub_ltoa): Fix cast when handling negative

Modified: trunk/grub2/kern/dl.c
===================================================================
--- trunk/grub2/kern/dl.c	2009-04-13 23:01:54 UTC (rev 2102)
+++ trunk/grub2/kern/dl.c	2009-04-13 23:03:50 UTC (rev 2103)
@@ -584,7 +584,7 @@
 grub_dl_t
 grub_dl_load_file (const char *filename)
 {
-  grub_file_t file;
+  grub_file_t file = NULL;
   grub_ssize_t size;
   void *core = 0;
   grub_dl_t mod = 0;
@@ -596,21 +596,31 @@
   size = grub_file_size (file);
   core = grub_malloc (size);
   if (! core)
-    goto failed;
+    {
+      grub_file_close (file);
+      return 0;
+    }
 
   if (grub_file_read (file, core, size) != (int) size)
-    goto failed;
+    {
+      grub_file_close (file);
+      grub_free (core);
+      return 0;
+    }
 
+  /* We must close this before we try to process dependencies.
+     Some disk backends do not handle gracefully multiple concurrent
+     opens of the same device.  */
+  grub_file_close (file);
+
   mod = grub_dl_load_core (core, size);
   if (! mod)
-    goto failed;
+    {
+      grub_free (core);
+      return 0;
+    }
   
   mod->ref_count = 0;
-
- failed:
-  grub_file_close (file);
-  grub_free (core);
-
   return mod;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.