Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH] perf trace: free intlist on filter_pids calloc failure
@ 2026-11-12  8:31 Gu Bin
  2026-11-12  8:42 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Gu Bin @ 2026-11-12  8:31 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() builds an intlist and stores its
entry count in trace->filter_pids.nr before allocating the entries
array.  If that calloc fails, the function jumps to the out label,
which returns without freeing the intlist: the option callback exits
perf with an error, so the leak is the only damage, but it is
triggered on every --filter-pids run under memory pressure.

Restructure the function so that every path that has created the
intlist also frees it: the failure path now falls through to
intlist__delete() as well, and the out label is gone.

Fixes: f078c3852c73 ("perf trace: Introduce --filter-pids")
Signed-off-by: Gu Bin <gubin@cmss.chinamobile.com>
---
 tools/perf/builtin-trace.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 4094141461f91..d435b35f1351c 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -5432,17 +5432,16 @@ static int trace__set_filter_pids_from_option(const struct option *opt, const ch
 	i = trace->filter_pids.nr = intlist__nr_entries(list) + 1;
 	trace->filter_pids.entries = calloc(i, sizeof(pid_t));
 
-	if (trace->filter_pids.entries == NULL)
-		goto out;
+	if (trace->filter_pids.entries) {
+		trace->filter_pids.entries[0] = getpid();
 
-	trace->filter_pids.entries[0] = getpid();
+		for (i = 1; i < trace->filter_pids.nr; ++i)
+			trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
 
-	for (i = 1; i < trace->filter_pids.nr; ++i)
-		trace->filter_pids.entries[i] = intlist__entry(list, i - 1)->i;
+		ret = 0;
+	}
 
 	intlist__delete(list);
-	ret = 0;
-out:
 	return ret;
 }
 
-- 
2.50.1.windows.1




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

end of thread, other threads:[~2026-11-12  8:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12  8:31 [PATCH] perf trace: free intlist on filter_pids calloc failure Gu Bin
2026-11-12  8:42 ` sashiko-bot

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