]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm: fix memory leak on mm_init error handling
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 30 Mar 2023 13:38:22 +0000 (09:38 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 5 Apr 2023 23:01:35 +0000 (16:01 -0700)
commit905d380c0f6d8d8f976538608aaf0ccf5b0bb77b
treeef1e265d1ea0477366e1c2f682ca6e91a2dbf3df
parent66f964a18f7bd698672c1dc5a3eafd5aa4d054f8
mm: fix memory leak on mm_init error handling

commit f1a7941243c1 ("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/20230330133822.66271-1-mathieu.desnoyers@efficios.com
Fixes: f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
kernel/fork.c