From 60de2c6561ae57b5f2c50efecc1fa1f0081f731a Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Mon, 13 Jul 2026 16:45:35 -0700 Subject: [PATCH] perf sched: Fix memory leaks in perf sched stats report The second pass data is not saved in the list and only used to calculate delta from the first pass. Let's free the data after use. Fixes: 5a357ae6ad63 ("perf sched stats: Add support for report subcommand") Reviewed-and-tested-by: Swapnil Sapkal Signed-off-by: Namhyung Kim --- tools/perf/builtin-sched.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index c5728f3aa46f..ab9590c4d838 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -4631,6 +4631,8 @@ static int perf_sched__process_schedstat(const struct perf_tool *tool __maybe_un domain_second_pass = list_first_entry(&cpu_second_pass->domain_head, struct schedstat_domain, domain_list); store_schedstat_cpu_diff(temp); + free(temp->cpu_data); + free(temp); } } else if (event->header.type == PERF_RECORD_SCHEDSTAT_DOMAIN) { struct schedstat_cpu *cpu_tail; @@ -4651,6 +4653,8 @@ static int perf_sched__process_schedstat(const struct perf_tool *tool __maybe_un } else { store_schedstat_domain_diff(temp); domain_second_pass = list_next_entry(domain_second_pass, domain_list); + free(temp->domain_data); + free(temp); } }