[PATCH] perf parse-events: free evsel and config terms if term conversion fails
From: Gu Bin
Date: Fri Nov 13 2026 - 05:49:33 EST
add_tracepoint() creates the evsel with evsel__newtp_idx() before
converting the user-supplied config terms with get_config_terms().
If a term allocation fails there, the function returns -ENOMEM with
the evsel not yet on any list, so nobody frees it, and the terms
that get_config_terms() already queued on the local config_terms
list are leaked as well.
Free the partially built config_terms list, then release the evsel
with evsel__put(), before returning.
Fixes: e637d17757a1 ("perf tools: Enable event_config terms to tracepoint events")
Signed-off-by: Gu Bin <gubin@xxxxxxxxxxxxxxxxxxxx>
---
tools/perf/util/parse-events.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index f3ba70d4f76b..e4f842532145 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -490,8 +490,11 @@ static int add_tracepoint(struct parse_events_state *parse_state,
if (head_config) {
LIST_HEAD(config_terms);
- if (get_config_terms(head_config, &config_terms))
+ if (get_config_terms(head_config, &config_terms)) {
+ free_config_terms(&config_terms);
+ evsel__put(evsel);
return -ENOMEM;
+ }
list_splice(&config_terms, &evsel->config_terms);
}
--
2.50.1.windows.1