Skip to content

Commit 1eb217a

Browse files
Faisal-523namhyung
authored andcommitted
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: cd63c22 ("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>
1 parent fe072f6 commit 1eb217a

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

tools/perf/util/parse-events.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,11 @@ __add_event(struct list_head *list, int *idx,
251251
event_attr_init(attr);
252252

253253
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+
}
256259

257260
if (name) {
258261
evsel->name = strdup(name);

0 commit comments

Comments
 (0)