]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf sched: Fix thread reference leak in idle hist processing
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 5 Jun 2026 14:15:58 +0000 (11:15 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 5 Jun 2026 22:17:31 +0000 (19:17 -0300)
timehist_sched_change_event() sets itr->last_thread to NULL at the end
of idle hist processing without calling thread__put() first.  The
thread reference was acquired via thread__get() in timehist_get_thread()
(line 2581), so every idle context switch leaks a thread reference when
--idle-hist is active.

Use thread__zput() to properly release the reference before clearing
the pointer.

Fixes: 5d8f17fb5822 ("perf sched timehist: Add -I/--idle-hist option")
Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-sched.c

index 4600d70b486104dd894081496f2600f1c5ddcbcf..c0cd3cbb602aa4c03f696d1d9ead7eb1fa2befee 100644 (file)
@@ -2940,7 +2940,7 @@ static int timehist_sched_change_event(const struct perf_tool *tool,
                        if (itr->cursor.nr)
                                callchain_append(&itr->callchain, &itr->cursor, t - tprev);
 
-                       itr->last_thread = NULL;
+                       thread__zput(itr->last_thread);
                }
 
                if (!sched->summary_only)