]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Fix few potential memory misusage.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 14 May 2011 20:26:52 +0000 (22:26 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Sat, 14 May 2011 20:26:52 +0000 (22:26 +0200)
* grub-core/font/font.c (load_font_index): Don't free char_index to
avoid double free.

ChangeLog
grub-core/font/font.c

index 01f216bfb496d9b50b8a20a16f1a776dfa453110..f316af0b1e02d7cdd71f9adbcea51c5f8f97eed6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-05-14  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       Fix few potential memory misusage.
+
+       * grub-core/font/font.c (load_font_index): Don't free char_index to
+       avoid double free.
+
 2011-05-14  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * docs/grub.texi (Installation): Fix several outdated claims.
index ef6caf77bb2d5046f073d47441f62f0ae06bb777..26eac4c0591434a3349162e8c25580ab5192bea3 100644 (file)
@@ -316,10 +316,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct
     return 1;
   font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t));
   if (!font->bmp_idx)
-    {
-      grub_free (font->char_index);
-      return 1;
-    }
+    return 1;
   grub_memset (font->bmp_idx, 0xff, 0x10000 * sizeof (grub_uint16_t));
 
 
@@ -494,7 +491,7 @@ grub_font_load (const char *filename)
 #endif
 
   /* Allocate the font object.  */
-  font = (grub_font_t) grub_malloc (sizeof (struct grub_font));
+  font = (grub_font_t) grub_zalloc (sizeof (struct grub_font));
   if (!font)
     goto fail;
 
@@ -640,6 +637,11 @@ grub_font_load (const char *filename)
   return 0;
 
 fail:
+  if (file)
+    grub_file_close (file);
+  if (font)
+    font->file = 0;
+
   free_font (font);
   return 1;
 }
@@ -799,6 +801,7 @@ free_font (grub_font_t font)
       grub_free (font->name);
       grub_free (font->family);
       grub_free (font->char_index);
+      grub_free (font->bmp_idx);
       grub_free (font);
     }
 }