Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf parse-events: Fix evsel allocation failure

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>

authored by

Faisal Bukhari and committed by
Namhyung Kim
1eb217ab fe072f65

+5 -2
+5 -2
tools/perf/util/parse-events.c
··· 251 251 event_attr_init(attr); 252 252 253 253 evsel = evsel__new_idx(attr, *idx); 254 - if (!evsel) 255 - goto out_err; 254 + if (!evsel) { 255 + perf_cpu_map__put(cpus); 256 + perf_cpu_map__put(pmu_cpus); 257 + return NULL; 258 + } 256 259 257 260 if (name) { 258 261 evsel->name = strdup(name);