* [PATCH for mm-stable] mm/damon/lru_sort: fix potential memory leak in damon_lru_sort_init()
@ 2022-07-14 17:04 SeongJae Park
0 siblings, 0 replies; only message in thread
From: SeongJae Park @ 2022-07-14 17:04 UTC (permalink / raw)
To: akpm; +Cc: damon, linux-mm, linux-kernel, SeongJae Park
'damon_lru_sort_init()' returns an error when 'damon_select_ops()' fails
without freeing 'ctx' which allocated before. This commit fixes the
potential memory leak by freeing 'ctx' under the situation.
Commit 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists
Sorting"), which caused the problem is not in the mainline but
mm-stable. Please meld this into the commit.
Fixes: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting")
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/lru_sort.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c
index c276736a071c..9de6f00a71c5 100644
--- a/mm/damon/lru_sort.c
+++ b/mm/damon/lru_sort.c
@@ -524,8 +524,10 @@ static int __init damon_lru_sort_init(void)
if (!ctx)
return -ENOMEM;
- if (damon_select_ops(ctx, DAMON_OPS_PADDR))
+ if (damon_select_ops(ctx, DAMON_OPS_PADDR)) {
+ damon_destroy_ctx(ctx);
return -EINVAL;
+ }
ctx->callback.after_wmarks_check = damon_lru_sort_after_wmarks_check;
ctx->callback.after_aggregation = damon_lru_sort_after_aggregation;
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-14 17:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 17:04 [PATCH for mm-stable] mm/damon/lru_sort: fix potential memory leak in damon_lru_sort_init() SeongJae Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).