From: Leo Yan <leo.yan@arm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Suyash Mahar <smahar@meta.com>, Amir Ayupov <aaupov@fb.com>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Leo Yan <leo.yan@arm.com>
Subject: [PATCH v2 3/7] perf stat: Release the initial evlist before opening the session
Date: Fri, 04 Dec 2026 11:23:25 +0000 [thread overview]
Message-ID: <20261204-perf_fix_large_threads-v2-3-a6c077f3037d@arm.com> (raw)
In-Reply-To: <20261204-perf_fix_large_threads-v2-0-a6c077f3037d@arm.com>
If perf_session__new() fails, __cmd_report() returns before the put.
cmd_stat() returns the result of __cmd_report() directly, bypassing
cleanup and leaking the initial evlist. Move the put before session
creation to cover this error path.
Fixes: 2b87be183bca ("perf stat: Avoid evlist leak")
Link: https://sashiko.dev/#/bug/linux-b77574e3-cc57-4338-8810-73a0cfa6fff7
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/perf/builtin-stat.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 92892581ccdcb28f20737f94b72406432b67e316..7b2025c37e87cff4ddcf7da8c643db008bdaed54 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2408,13 +2408,19 @@ static int __cmd_report(int argc, const char **argv)
perf_stat.tool.stat = perf_event__process_stat_event;
perf_stat.tool.stat_round = process_stat_round_event;
+ /*
+ * The session creates its own evlist. If perf_session__new() fails,
+ * cmd_stat() returns without releasing the initial evlist, so drop
+ * it here.
+ */
+ evlist__put(evsel_list);
+
session = perf_session__new(&perf_stat.data, &perf_stat.tool);
if (IS_ERR(session))
return PTR_ERR(session);
perf_stat.session = session;
stat_config.output = stderr;
- evlist__put(evsel_list);
evsel_list = session->evlist;
ret = perf_session__process_events(session);
--
2.34.1
next prev parent reply other threads:[~2026-12-04 11:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
2026-12-04 11:23 ` [PATCH v2 1/7] perf stat: Release aggregation maps on report exit Leo Yan
2026-12-04 11:23 ` [PATCH v2 2/7] perf stat: Drop CPU and thread map references " Leo Yan
2026-12-04 11:23 ` Leo Yan [this message]
2026-12-04 11:23 ` [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records Leo Yan
2026-12-04 12:15 ` sashiko-bot
2026-12-04 12:31 ` Leo Yan
2026-12-04 11:23 ` [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report Leo Yan
2026-12-04 12:39 ` sashiko-bot
2026-12-04 11:23 ` [PATCH v2 6/7] perf test: Cover multi-record thread map synthesis Leo Yan
2026-12-04 13:22 ` sashiko-bot
2026-12-04 11:23 ` [PATCH v2 7/7] perf docs: Describe multi-record thread maps Leo Yan
2026-12-04 13:22 ` [PATCH v2 0/7] perf: Support thread maps larger than one record sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204-perf_fix_large_threads-v2-3-a6c077f3037d@arm.com \
--to=leo.yan@arm.com \
--cc=aaupov@fb.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=namhyung@kernel.org \
--cc=smahar@meta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox