Commit 32d6feadf4e17ea9b98071be9bbf402a74a4f818
Committed by
Linus Torvalds
1 parent
29c1f677d4
Exists in
master
and in
7 other branches
mm/hugetlb.c: fix error-path memory leak in nr_hugepages_store_common()
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>
Showing 1 changed file with 3 additions and 1 deletions Side-by-side Diff
mm/hugetlb.c
... | ... | @@ -1374,8 +1374,10 @@ |
1374 | 1374 | NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY); |
1375 | 1375 | |
1376 | 1376 | err = strict_strtoul(buf, 10, &count); |
1377 | - if (err) | |
1377 | + if (err) { | |
1378 | + NODEMASK_FREE(nodes_allowed); | |
1378 | 1379 | return 0; |
1380 | + } | |
1379 | 1381 | |
1380 | 1382 | h = kobj_to_hstate(kobj, &nid); |
1381 | 1383 | if (nid == NUMA_NO_NODE) { |