* [PATCH] perf trace: free filter_pids entries in trace__exit()
@ 2026-11-17 9:56 Gu Bin
2026-11-17 9:56 ` [PATCH] perf parse-events: free partially copied terms if term cloning fails Gu Bin
2026-11-17 10:03 ` [PATCH] perf trace: free filter_pids entries in trace__exit() sashiko-bot
0 siblings, 2 replies; 4+ messages in thread
From: Gu Bin @ 2026-11-17 9:56 UTC (permalink / raw)
To: acme
Cc: peterz, mingo, namhyung, mark.rutland, alexander.shishkin, jolsa,
irogers, adrian.hunter, james.clark, linux-perf-users,
linux-kernel
trace__set_filter_pids_from_option() allocates trace->filter_pids.entries
with calloc() when the --filter-pids option is parsed, but trace__exit()
never frees it. Free it there along with the other entries array of the
trace struct, ev_qualifier_ids.
Fixes: f078c3852c73 ("perf trace: Introduce --filter-pids")
Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
---
tools/perf/builtin-trace.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 4094141461f91..9bd95be106d19 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -5755,6 +5755,7 @@ static void trace__exit(struct trace *trace)
thread__zput(trace->current);
strlist__delete(trace->ev_qualifier);
zfree(&trace->ev_qualifier_ids.entries);
+ zfree(&trace->filter_pids.entries);
if (trace->syscalls.table) {
for (size_t i = 0; i < trace->syscalls.table_size; i++)
syscall__delete(trace->syscalls.table[i]);
--
2.50.1.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] perf parse-events: free partially copied terms if term cloning fails 2026-11-17 9:56 [PATCH] perf trace: free filter_pids entries in trace__exit() Gu Bin @ 2026-11-17 9:56 ` Gu Bin 2026-11-17 10:06 ` sashiko-bot 2026-11-17 10:03 ` [PATCH] perf trace: free filter_pids entries in trace__exit() sashiko-bot 1 sibling, 1 reply; 4+ messages in thread From: Gu Bin @ 2026-11-17 9:56 UTC (permalink / raw) To: acme Cc: peterz, mingo, namhyung, mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter, james.clark, linux-perf-users, linux-kernel parse_events_terms__copy() clones the terms of src into dest one by one and stops as soon as parse_events_term__clone() fails, leaving the terms cloned so far queued on dest->terms. Both callers, parse_events_add_pmu() and parse_events_multi_pmu_add(), return on that error without freeing the local parsed_terms, so the partially copied terms and their strings are leaked. Free the local terms with parse_events_terms__exit() before returning, as both functions already do on their later error paths. Fixes: 0d3f0e6f94ef ("perf parse-events: Introduce 'struct parse_events_terms'") Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com> --- tools/perf/util/parse-events.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index f3ba70d4f76b..8ab02a2fe1c3 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1539,8 +1539,10 @@ static int parse_events_add_pmu(struct parse_events_state *parse_state, if (const_parsed_terms) { int ret = parse_events_terms__copy(const_parsed_terms, &parsed_terms); - if (ret) + if (ret) { + parse_events_terms__exit(&parsed_terms); return ret; + } } fix_raw(&parsed_terms, pmu); @@ -1642,8 +1644,10 @@ int parse_events_multi_pmu_add(struct parse_events_state *parse_state, if (const_parsed_terms) { int ret = parse_events_terms__copy(const_parsed_terms, &parsed_terms); - if (ret) + if (ret) { + parse_events_terms__exit(&parsed_terms); return ret; + } } config = strdup(event_name); -- 2.50.1.windows.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] perf parse-events: free partially copied terms if term cloning fails 2026-11-17 9:56 ` [PATCH] perf parse-events: free partially copied terms if term cloning fails Gu Bin @ 2026-11-17 10:06 ` sashiko-bot 0 siblings, 0 replies; 4+ messages in thread From: sashiko-bot @ 2026-11-17 10:06 UTC (permalink / raw) To: Gu Bin; +Cc: linux-perf-users > parse_events_terms__copy() clones the terms of src into dest one by > one and stops as soon as parse_events_term__clone() fails, leaving the > terms cloned so far queued on dest->terms. Both callers, > parse_events_add_pmu() and parse_events_multi_pmu_add(), return on > that error without freeing the local parsed_terms, so the partially > copied terms and their strings are leaked. > > Free the local terms with parse_events_terms__exit() before > returning, as both functions already do on their later error paths. > > Fixes: 0d3f0e6f94ef ("perf parse-events: Introduce 'struct parse_events_terms'") > Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com> Sashiko has reviewed this patch and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261117095603.2397-2-gubin@cmss.chinamobile.com?part=1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] perf trace: free filter_pids entries in trace__exit() 2026-11-17 9:56 [PATCH] perf trace: free filter_pids entries in trace__exit() Gu Bin 2026-11-17 9:56 ` [PATCH] perf parse-events: free partially copied terms if term cloning fails Gu Bin @ 2026-11-17 10:03 ` sashiko-bot 1 sibling, 0 replies; 4+ messages in thread From: sashiko-bot @ 2026-11-17 10:03 UTC (permalink / raw) To: Gu Bin; +Cc: linux-perf-users > trace__set_filter_pids_from_option() allocates trace->filter_pids.entries > with calloc() when the --filter-pids option is parsed, but trace__exit() > never frees it. Free it there along with the other entries array of the > trace struct, ev_qualifier_ids. > > Fixes: f078c3852c73 ("perf trace: Introduce --filter-pids") > Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com> Sashiko has reviewed this patch and found no issues. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261117095603.2397-1-gubin@cmss.chinamobile.com?part=1 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-17 10:06 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-17 9:56 [PATCH] perf trace: free filter_pids entries in trace__exit() Gu Bin 2026-11-17 9:56 ` [PATCH] perf parse-events: free partially copied terms if term cloning fails Gu Bin 2026-11-17 10:06 ` sashiko-bot 2026-11-17 10:03 ` [PATCH] perf trace: free filter_pids entries in trace__exit() sashiko-bot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox