public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Jackie Liu <liu.yun@linux.dev>
To: sj@kernel.org
Cc: akpm@linux-foundation.org, linux-mm@kvack.org
Subject: [PATCH] mm/damon/stat: fix memory leak on damon_start() failure in damon_stat_start()
Date: Tue, 31 Mar 2026 18:15:53 +0800	[thread overview]
Message-ID: <20260331101553.88422-1-liu.yun@linux.dev> (raw)

From: Jackie Liu <liuyun01@kylinos.cn>

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.

Fixes: 369c415e6073 ("mm/damon: introduce DAMON_STAT module")
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 mm/damon/stat.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/damon/stat.c b/mm/damon/stat.c
index cf2c5a541eee..5a742fc157e4 100644
--- a/mm/damon/stat.c
+++ b/mm/damon/stat.c
@@ -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;
-- 
2.51.1



             reply	other threads:[~2026-03-31 10:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31 10:15 Jackie Liu [this message]
2026-04-01  1:24 ` (sashiko review) [PATCH] mm/damon/stat: fix memory leak on damon_start() failure in damon_stat_start() SeongJae Park
2026-04-01  1:32 ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260331101553.88422-1-liu.yun@linux.dev \
    --to=liu.yun@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=sj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox