Commit ec1658f0 authored by SeongJae Park's avatar SeongJae Park Committed by akpm

mm/damon/lru_sort: fix potential memory leak in damon_lru_sort_init()

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.

Link: https://lkml.kernel.org/r/20220714170458.49727-1-sj@kernel.org
Fixes: 40e983cc ("mm/damon: introduce DAMON-based LRU-lists Sorting")
Signed-off-by: default avatarSeongJae Park <sj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 4f2930c6
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment