Skip to content

Commit cc2d86b

Browse files
Stephane Eranianacmel
authored andcommitted
perf evlist: Fix missing event name init for default event
When no event is given to perf record, perf top, a default event is initialized (cycles). However, perf_evlist__add_default() was not setting the symbolic name for the event. Perf top worked simply because it was reconstructing the name from the event code. But it should not have to do this. This patch initializes the evsel->name field properly. This second version improves the code flow on the non error path. Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20110607161936.GA8163@quad Signed-off-by: Stephane Eranian <eranian@google.com> [committer note: Use perf_evsel__delete() instead of plain free()] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 77e5729 commit cc2d86b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎tools/perf/util/evlist.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,19 @@ int perf_evlist__add_default(struct perf_evlist *evlist)
8585
struct perf_evsel *evsel = perf_evsel__new(&attr, 0);
8686

8787
if (evsel == NULL)
88-
return -ENOMEM;
88+
goto error;
89+
90+
/* use strdup() because free(evsel) assumes name is allocated */
91+
evsel->name = strdup("cycles");
92+
if (!evsel->name)
93+
goto error_free;
8994

9095
perf_evlist__add(evlist, evsel);
9196
return 0;
97+
error_free:
98+
perf_evsel__delete(evsel);
99+
error:
100+
return -ENOMEM;
92101
}
93102

94103
void perf_evlist__disable(struct perf_evlist *evlist)

0 commit comments

Comments
 (0)