]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/kern/emu/hostdisk.c
authorColin Watson <cjwatson@ubuntu.com>
Fri, 17 Sep 2010 10:43:46 +0000 (11:43 +0100)
committerColin Watson <cjwatson@ubuntu.com>
Fri, 17 Sep 2010 10:43:46 +0000 (11:43 +0100)
(convert_system_partition_to_system_disk): Fix devmapper memory pool
leak.
Reported and based on patch by: Modestas Vainius.

ChangeLog
grub-core/kern/emu/hostdisk.c

index 7f5ba2d44d1db76a4aa6c9770a62af0e98254547..9638bc63346eb2b62076b9b7d57f54f9627286d9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-09-17  Colin Watson  <cjwatson@ubuntu.com>
+
+       * grub-core/kern/emu/hostdisk.c
+       (convert_system_partition_to_system_disk): Fix devmapper memory pool
+       leak.
+       Reported and based on patch by: Modestas Vainius.
+
 2010-09-17  Colin Watson  <cjwatson@ubuntu.com>
 
        Fix DM-RAID probing with recent versions of device-mapper udev
index 69c5ed921c295c87f5a99011c7ef52cc473abd94..a9b94e2121cbae3495e016ad20cf538e15c00efd 100644 (file)
@@ -1161,19 +1161,17 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
          /dev/mapper/ are often symlinks.  */
       if ((strncmp ("/dev/mapper/", os_dev, 12) == 0))
        {
-         static struct dm_tree *tree = NULL;
+         struct dm_tree *tree;
          uint32_t maj, min;
          struct dm_tree_node *node, *child;
          void *handle;
-         const char *node_uuid, *mapper_name, *child_uuid, *child_name;
-
-         if (! tree)
-           tree = dm_tree_create ();
+         const char *node_uuid, *mapper_name = NULL, *child_uuid, *child_name;
 
+         tree = dm_tree_create ();
          if (! tree)
            {
              grub_dprintf ("hostdisk", "dm_tree_create failed\n");
-             return NULL;
+             goto devmapper_out;
            }
 
          maj = major (st->st_rdev);
@@ -1181,29 +1179,30 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
          if (! dm_tree_add_dev (tree, maj, min))
            {
              grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n");
-             return NULL;
+             goto devmapper_out;
            }
 
          node = dm_tree_find_node (tree, maj, min);
          if (! node)
            {
              grub_dprintf ("hostdisk", "dm_tree_find_node failed\n");
-             return NULL;
+             goto devmapper_out;
            }
          node_uuid = dm_tree_node_get_uuid (node);
          if (! node_uuid)
            {
              grub_dprintf ("hostdisk", "%s has no DM uuid\n", path);
-             return NULL;
+             node = NULL;
+             goto devmapper_out;
            }
          else if (strncmp (node_uuid, "DMRAID-", 7) != 0)
            {
              grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path);
-             return NULL;
+             node = NULL;
+             goto devmapper_out;
            }
 
          handle = NULL;
-         mapper_name = NULL;
          /* Counter-intuitively, device-mapper refers to the disk-like
             device containing a DM-RAID partition device as a "child" of
             the partition device.  */
@@ -1233,17 +1232,20 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
          mapper_name = child_name;
 
 devmapper_out:
-         if (! mapper_name)
+         if (! mapper_name && node)
            {
              /* This is a DM-RAID disk, not a partition.  */
              mapper_name = dm_tree_node_get_name (node);
              if (! mapper_name)
-               {
-                 grub_dprintf ("hostdisk", "%s has no DM name\n", path);
-                 return NULL;
-               }
+               grub_dprintf ("hostdisk", "%s has no DM name\n", path);
            }
-         return xasprintf ("/dev/mapper/%s", mapper_name);
+         if (tree)
+           dm_tree_free (tree);
+         free (path);
+         if (mapper_name)
+           return xasprintf ("/dev/mapper/%s", mapper_name);
+         else
+           return NULL;
        }
 #endif /* HAVE_DEVICE_MAPPER */
     }