* [PATCH v2 0/3] perf sched stats: Fix memory leaks
@ 2026-07-13 23:45 Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 1/3] perf sched: Add missing perf_session__delete() Namhyung Kim
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Namhyung Kim @ 2026-07-13 23:45 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Hello,
This is a small series to fix memory leaks in the perf sched stats.
I've tested the changes with the address sanitizer.
v2 changes)
* remove invalid file closing (Sashiko)
Thanks,
Namhyung
Namhyung Kim (3):
perf sched: Add missing perf_session__delete()
perf sched: Fix memory leaks in perf sched stats report
perf sched: Free subcommand string after perf sched stats
tools/perf/builtin-sched.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
--
2.55.0.795.g602f6c329a-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/3] perf sched: Add missing perf_session__delete()
2026-07-13 23:45 [PATCH v2 0/3] perf sched stats: Fix memory leaks Namhyung Kim
@ 2026-07-13 23:45 ` Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 2/3] perf sched: Fix memory leaks in perf sched stats report Namhyung Kim
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2026-07-13 23:45 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users,
Swapnil Sapkal
The perf sched stats record missed to release the session and ASAN
reported a leak.
Fixes: c3030995f23b ("perf sched stats: Add record and rawdump support")
Cc: Swapnil Sapkal <swapnil.sapkal@amd.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-sched.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 6e0d8f4d270e2d88..c5728f3aa46f2630 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -4027,8 +4027,8 @@ static int perf_sched__schedstat_record(struct perf_sched *sched,
else
fprintf(stderr, "[ perf sched stats: Failed !! ]\n");
+ perf_session__delete(session);
evlist__put(evlist);
- close(fd);
return err;
}
--
2.55.0.795.g602f6c329a-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/3] perf sched: Fix memory leaks in perf sched stats report
2026-07-13 23:45 [PATCH v2 0/3] perf sched stats: Fix memory leaks Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 1/3] perf sched: Add missing perf_session__delete() Namhyung Kim
@ 2026-07-13 23:45 ` Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 3/3] perf sched: Free subcommand string after perf sched stats Namhyung Kim
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2026-07-13 23:45 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users,
Swapnil Sapkal
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")
Cc: Swapnil Sapkal <swapnil.sapkal@amd.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
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 c5728f3aa46f2630..ab9590c4d838eff3 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);
}
}
--
2.55.0.795.g602f6c329a-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 3/3] perf sched: Free subcommand string after perf sched stats
2026-07-13 23:45 [PATCH v2 0/3] perf sched stats: Fix memory leaks Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 1/3] perf sched: Add missing perf_session__delete() Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 2/3] perf sched: Fix memory leaks in perf sched stats report Namhyung Kim
@ 2026-07-13 23:45 ` Namhyung Kim
2026-07-15 18:01 ` [PATCH v2 0/3] perf sched stats: Fix memory leaks Swapnil Sapkal
2026-07-16 16:58 ` Namhyung Kim
4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2026-07-13 23:45 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users,
Swapnil Sapkal
The first entry of the sched_usage is dynamically allocated in
parse_options_subcommand() so it should be released at the end.
Do not return from a subcommand directly.
Fixes: 064790a3d4a8 ("perf sched stats: Add support for diff subcommand")
Cc: Swapnil Sapkal <swapnil.sapkal@amd.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-sched.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index ab9590c4d838eff3..acc8d81a20d3b9d1 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -5259,19 +5259,20 @@ int cmd_sched(int argc, const char **argv)
if (argc)
argc = parse_options(argc, argv, stats_options,
stats_usage, 0);
- return perf_sched__schedstat_record(&sched, argc, argv);
+ ret = perf_sched__schedstat_record(&sched, argc, argv);
} else if (argv[0] && !strcmp(argv[0], "report")) {
if (argc)
argc = parse_options(argc, argv, stats_options,
stats_usage, 0);
- return perf_sched__schedstat_report(&sched);
+ ret = perf_sched__schedstat_report(&sched);
} else if (argv[0] && !strcmp(argv[0], "diff")) {
if (argc)
argc = parse_options(argc, argv, stats_options,
stats_usage, 0);
- return perf_sched__schedstat_diff(&sched, argc, argv);
+ ret = perf_sched__schedstat_diff(&sched, argc, argv);
+ } else {
+ ret = perf_sched__schedstat_live(&sched, argc, argv);
}
- return perf_sched__schedstat_live(&sched, argc, argv);
} else {
usage_with_options(sched_usage, sched_options);
}
--
2.55.0.795.g602f6c329a-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] perf sched stats: Fix memory leaks
2026-07-13 23:45 [PATCH v2 0/3] perf sched stats: Fix memory leaks Namhyung Kim
` (2 preceding siblings ...)
2026-07-13 23:45 ` [PATCH v2 3/3] perf sched: Free subcommand string after perf sched stats Namhyung Kim
@ 2026-07-15 18:01 ` Swapnil Sapkal
2026-07-16 16:58 ` Namhyung Kim
4 siblings, 0 replies; 6+ messages in thread
From: Swapnil Sapkal @ 2026-07-15 18:01 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Ian Rogers, Jiri Olsa, Adrian Hunter,
James Clark, Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
Hello Namhyung,
On 14-07-2026 05:15, Namhyung Kim wrote:
> Hello,
>
> This is a small series to fix memory leaks in the perf sched stats.
> I've tested the changes with the address sanitizer.
>
Reviewed-and-tested-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
> v2 changes)
> * remove invalid file closing (Sashiko)
>
>
> Thanks,
> Namhyung
>
>
> Namhyung Kim (3):
> perf sched: Add missing perf_session__delete()
> perf sched: Fix memory leaks in perf sched stats report
> perf sched: Free subcommand string after perf sched stats
>
> tools/perf/builtin-sched.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
--
Thanks and Regards,
Swapnil
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 0/3] perf sched stats: Fix memory leaks
2026-07-13 23:45 [PATCH v2 0/3] perf sched stats: Fix memory leaks Namhyung Kim
` (3 preceding siblings ...)
2026-07-15 18:01 ` [PATCH v2 0/3] perf sched stats: Fix memory leaks Swapnil Sapkal
@ 2026-07-16 16:58 ` Namhyung Kim
4 siblings, 0 replies; 6+ messages in thread
From: Namhyung Kim @ 2026-07-16 16:58 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Namhyung Kim
Cc: Ian Rogers, Jiri Olsa, Adrian Hunter, James Clark,
Peter Zijlstra, Ingo Molnar, LKML, linux-perf-users
On Mon, 13 Jul 2026 16:45:33 -0700, Namhyung Kim wrote:
> This is a small series to fix memory leaks in the perf sched stats.
> I've tested the changes with the address sanitizer.
>
> v2 changes)
> * remove invalid file closing (Sashiko)
>
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-07-16 16:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-13 23:45 [PATCH v2 0/3] perf sched stats: Fix memory leaks Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 1/3] perf sched: Add missing perf_session__delete() Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 2/3] perf sched: Fix memory leaks in perf sched stats report Namhyung Kim
2026-07-13 23:45 ` [PATCH v2 3/3] perf sched: Free subcommand string after perf sched stats Namhyung Kim
2026-07-15 18:01 ` [PATCH v2 0/3] perf sched stats: Fix memory leaks Swapnil Sapkal
2026-07-16 16:58 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox