Skip to content

Commit b20b036

Browse files
compudjakpm00
authored andcommitted
mm: fix memory leak on mm_init error handling
commit f1a7941 ("mm: convert mm's rss stats into percpu_counter") introduces a memory leak by missing a call to destroy_context() when a percpu_counter fails to allocate. Before introducing the per-cpu counter allocations, init_new_context() was the last call that could fail in mm_init(), and thus there was no need to ever invoke destroy_context() in the error paths. Adding the following percpu counter allocations adds error paths after init_new_context(), which means its associated destroy_context() needs to be called when percpu counters fail to allocate. Link: https://lkml.kernel.org/r/[email protected] Fixes: f1a7941 ("mm: convert mm's rss stats into percpu_counter") Signed-off-by: Mathieu Desnoyers <[email protected]> Acked-by: Shakeel Butt <[email protected]> Cc: Marek Szyprowski <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 1007843 commit b20b036

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

kernel/fork.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
11741174
fail_pcpu:
11751175
while (i > 0)
11761176
percpu_counter_destroy(&mm->rss_stat[--i]);
1177+
destroy_context(mm);
11771178
fail_nocontext:
11781179
mm_free_pgd(mm);
11791180
fail_nopgd:

0 commit comments

Comments
 (0)