1
Description: Fix devmapper memory pool leak with DM-RAID
2
Author: Modestas Vainius <modax@debian.org>
3
Author: Colin Watson <cjwatson@debian.org>
4
Origin: upstream, http://bazaar.launchpad.net/~vcs-imports/grub/grub2-bzr/revision/2781
6
Last-Update: 2010-09-17
8
Index: b/kern/emu/hostdisk.c
9
===================================================================
10
--- a/kern/emu/hostdisk.c
11
+++ b/kern/emu/hostdisk.c
12
@@ -1164,19 +1164,17 @@
13
/dev/mapper/ are often symlinks. */
14
if ((strncmp ("/dev/mapper/", os_dev, 12) == 0))
16
- static struct dm_tree *tree = NULL;
17
+ struct dm_tree *tree;
19
- struct dm_tree_node *node, *child;
20
+ struct dm_tree_node *node = NULL, *child;
22
- const char *node_uuid, *mapper_name, *child_uuid, *child_name;
25
- tree = dm_tree_create ();
26
+ const char *node_uuid, *mapper_name = NULL, *child_uuid, *child_name;
28
+ tree = dm_tree_create ();
31
grub_dprintf ("hostdisk", "dm_tree_create failed\n");
36
maj = major (st->st_rdev);
37
@@ -1184,29 +1182,30 @@
38
if (! dm_tree_add_dev (tree, maj, min))
40
grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n");
45
node = dm_tree_find_node (tree, maj, min);
48
grub_dprintf ("hostdisk", "dm_tree_find_node failed\n");
52
node_uuid = dm_tree_node_get_uuid (node);
55
grub_dprintf ("hostdisk", "%s has no DM uuid\n", path);
60
else if (strncmp (node_uuid, "DMRAID-", 7) != 0)
62
grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path);
70
/* Counter-intuitively, device-mapper refers to the disk-like
71
device containing a DM-RAID partition device as a "child" of
72
the partition device. */
73
@@ -1236,17 +1235,20 @@
74
mapper_name = child_name;
78
+ if (! mapper_name && node)
80
/* This is a DM-RAID disk, not a partition. */
81
mapper_name = dm_tree_node_get_name (node);
84
- grub_dprintf ("hostdisk", "%s has no DM name\n", path);
87
+ grub_dprintf ("hostdisk", "%s has no DM name\n", path);
89
- return xasprintf ("/dev/mapper/%s", mapper_name);
91
+ dm_tree_free (tree);
94
+ return xasprintf ("/dev/mapper/%s", mapper_name);
98
#endif /* HAVE_DEVICE_MAPPER */