]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf parse-events: Fix evsel allocation failure
authorFaisal Bukhari <faisalbukhari523@gmail.com>
Mon, 22 Sep 2025 18:08:34 +0000 (23:38 +0530)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 6 Jan 2026 22:54:24 +0000 (14:54 -0800)
If evsel__new_idx() returns NULL, the function currently jumps to label
'out_err'.  Here, references to `cpus` and `pmu_cpus` are dropped.
Also, resources held by evsel->name and evsel->metric_id are freed.

But if evsel__new_idx() returns NULL, it can lead to NULL pointer
dereference.

Fixes: cd63c22168257a0b ("perf parse-events: Minor __add_event refactoring")
Signed-off-by: Faisal Bukhari <faisalbukhari523@gmail.com>
Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/parse-events.c

index 17c1c36a7bf9a3ec08812c4de700e3a3b3e547cc..000c89a1e50d7b700ff4d4a0dfb1496a9ad40fbb 100644 (file)
@@ -251,8 +251,11 @@ __add_event(struct list_head *list, int *idx,
                event_attr_init(attr);
 
        evsel = evsel__new_idx(attr, *idx);
-       if (!evsel)
-               goto out_err;
+       if (!evsel) {
+               perf_cpu_map__put(cpus);
+               perf_cpu_map__put(pmu_cpus);
+               return NULL;
+       }
 
        if (name) {
                evsel->name = strdup(name);