]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
mm/hugetlb.c: fix error-path memory leak in nr_hugepages_store_common()
authorJesper Juhl <jj@chaosbits.net>
Thu, 13 Jan 2011 23:47:22 +0000 (15:47 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 14 Jan 2011 01:32:48 +0000 (17:32 -0800)
The NODEMASK_ALLOC macro may dynamically allocate memory for its second
argument ('nodes_allowed' in this context).

In nr_hugepages_store_common() we may abort early if strict_strtoul()
fails, but in that case we do not free the memory already allocated to
'nodes_allowed', causing a memory leak.

This patch closes the leak by freeing the memory in the error path.

[akpm@linux-foundation.org: use NODEMASK_FREE, per Minchan Kim]
Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Cc: Minchan Kim <minchan.kim@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/hugetlb.c

index 7bf223d6677b77ca0322645313d90467310362a4..8e31cda6fc2209fb5b6cff56245f611d7850b2fe 100644 (file)
@@ -1374,8 +1374,10 @@ static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
        NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
 
        err = strict_strtoul(buf, 10, &count);
-       if (err)
+       if (err) {
+               NODEMASK_FREE(nodes_allowed);
                return 0;
+       }
 
        h = kobj_to_hstate(kobj, &nid);
        if (nid == NUMA_NO_NODE) {