util/grub-install: rearrange code to avoid memory leak.
authorAndrei Borzenkov <arvidjaar@gmail.com>
Mon, 26 Jan 2015 19:17:31 +0000 (22:17 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Mon, 26 Jan 2015 20:04:09 +0000 (23:04 +0300)
Found by: Coverity scan.

util/grub-install.c

index afbc557..210f4a7 100644 (file)
@@ -615,17 +615,14 @@ device_map_check_duplicates (const char *dev_map)
   char **d;
   size_t i;
 
-  d = xmalloc (alloced * sizeof (d[0]));
-
   if (dev_map[0] == '\0')
     return;
 
   fp = grub_util_fopen (dev_map, "r");
   if (! fp)
-    {
-      free (d);
-      return;
-    }
+    return;
+
+  d = xmalloc (alloced * sizeof (d[0]));
 
   while (fgets (buf, sizeof (buf), fp))
     {