public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
* [PATCH] mm/damon/stat: fix memory leak on damon_start() failure in damon_stat_start()
@ 2026-03-31 10:15 Jackie Liu
  2026-04-01  1:24 ` (sashiko review) " SeongJae Park
  2026-04-01  1:32 ` SeongJae Park
  0 siblings, 2 replies; 3+ messages in thread
From: Jackie Liu @ 2026-03-31 10:15 UTC (permalink / raw)
  To: sj; +Cc: akpm, linux-mm

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-01  1:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 10:15 [PATCH] mm/damon/stat: fix memory leak on damon_start() failure in damon_stat_start() Jackie Liu
2026-04-01  1:24 ` (sashiko review) " SeongJae Park
2026-04-01  1:32 ` SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox