]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/damon/stat: fix memory leak on damon_start() failure in damon_stat_start()
authorJackie Liu <liuyun01@kylinos.cn>
Tue, 31 Mar 2026 10:15:53 +0000 (18:15 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 18 Apr 2026 07:10:51 +0000 (00:10 -0700)
Destroy the DAMON context and reset the global pointer when damon_start()
fails.  Otherwise, the context allocated by damon_stat_build_ctx() is
leaked, and the stale damon_stat_context pointer will be overwritten on
the next enable attempt, making the old allocation permanently
unreachable.

Link: https://lore.kernel.org/20260331101553.88422-1-liu.yun@linux.dev
Fixes: 369c415e6073 ("mm/damon: introduce DAMON_STAT module")
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
Reviewed-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 6.17.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/stat.c

index cf2c5a541eeeaab349c728a01337adf0859ba108..5a742fc157e4c79ebc9380658aefa7a78459025a 100644 (file)
@@ -249,8 +249,11 @@ static int damon_stat_start(void)
        if (!damon_stat_context)
                return -ENOMEM;
        err = damon_start(&damon_stat_context, 1, true);
-       if (err)
+       if (err) {
+               damon_destroy_ctx(damon_stat_context);
+               damon_stat_context = NULL;
                return err;
+       }
 
        damon_stat_last_refresh_jiffies = jiffies;
        call_control.data = damon_stat_context;