~ubuntu-core-dev/ubuntu/maverick/grub2/maverick

« back to all changes in this revision

Viewing changes to debian/patches/dmraid_pool_leak.patch

  • Committer: Colin Watson
  • Date: 2010-09-19 22:54:11 UTC
  • mfrom: (1892.1.300 grub)
  • Revision ID: cjwatson@canonical.com-20100919225411-9d09pttxo2ry5rfb
merge from Debian 1.98+20100804-5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
Forwarded: yes
 
6
Last-Update: 2010-09-17
 
7
 
 
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))
 
15
        {
 
16
-         static struct dm_tree *tree = NULL;
 
17
+         struct dm_tree *tree;
 
18
          uint32_t maj, min;
 
19
-         struct dm_tree_node *node, *child;
 
20
+         struct dm_tree_node *node = NULL, *child;
 
21
          void *handle;
 
22
-         const char *node_uuid, *mapper_name, *child_uuid, *child_name;
 
23
-
 
24
-         if (! tree)
 
25
-           tree = dm_tree_create ();
 
26
+         const char *node_uuid, *mapper_name = NULL, *child_uuid, *child_name;
 
27
 
 
28
+         tree = dm_tree_create ();
 
29
          if (! tree)
 
30
            {
 
31
              grub_dprintf ("hostdisk", "dm_tree_create failed\n");
 
32
-             return NULL;
 
33
+             goto devmapper_out;
 
34
            }
 
35
 
 
36
          maj = major (st->st_rdev);
 
37
@@ -1184,29 +1182,30 @@
 
38
          if (! dm_tree_add_dev (tree, maj, min))
 
39
            {
 
40
              grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n");
 
41
-             return NULL;
 
42
+             goto devmapper_out;
 
43
            }
 
44
 
 
45
          node = dm_tree_find_node (tree, maj, min);
 
46
          if (! node)
 
47
            {
 
48
              grub_dprintf ("hostdisk", "dm_tree_find_node failed\n");
 
49
-             return NULL;
 
50
+             goto devmapper_out;
 
51
            }
 
52
          node_uuid = dm_tree_node_get_uuid (node);
 
53
          if (! node_uuid)
 
54
            {
 
55
              grub_dprintf ("hostdisk", "%s has no DM uuid\n", path);
 
56
-             return NULL;
 
57
+             node = NULL;
 
58
+             goto devmapper_out;
 
59
            }
 
60
          else if (strncmp (node_uuid, "DMRAID-", 7) != 0)
 
61
            {
 
62
              grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path);
 
63
-             return NULL;
 
64
+             node = NULL;
 
65
+             goto devmapper_out;
 
66
            }
 
67
 
 
68
          handle = NULL;
 
69
-         mapper_name = NULL;
 
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;
 
75
 
 
76
 devmapper_out:
 
77
-         if (! mapper_name)
 
78
+         if (! mapper_name && node)
 
79
            {
 
80
              /* This is a DM-RAID disk, not a partition.  */
 
81
              mapper_name = dm_tree_node_get_name (node);
 
82
              if (! mapper_name)
 
83
-               {
 
84
-                 grub_dprintf ("hostdisk", "%s has no DM name\n", path);
 
85
-                 return NULL;
 
86
-               }
 
87
+               grub_dprintf ("hostdisk", "%s has no DM name\n", path);
 
88
            }
 
89
-         return xasprintf ("/dev/mapper/%s", mapper_name);
 
90
+         if (tree)
 
91
+           dm_tree_free (tree);
 
92
+         free (path);
 
93
+         if (mapper_name)
 
94
+           return xasprintf ("/dev/mapper/%s", mapper_name);
 
95
+         else
 
96
+           return NULL;
 
97
        }
 
98
 #endif /* HAVE_DEVICE_MAPPER */
 
99
     }