Skip to content

Commit be59dba

Browse files
captain5050namhyung
authored andcommitted
libperf evsel: Add missed puts and asserts
A missed evsel__close before evsel__delete was the source of leaking perf events due to a hybrid test. Add asserts in debug builds so that this shouldn't happen in the future. Add puts missing on the cpu map and thread maps. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent eda9e47 commit be59dba

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/lib/perf/evsel.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
4242

4343
void perf_evsel__delete(struct perf_evsel *evsel)
4444
{
45+
assert(evsel->fd == NULL); /* If not fds were not closed. */
46+
assert(evsel->mmap == NULL); /* If not munmap wasn't called. */
47+
assert(evsel->sample_id == NULL); /* If not free_id wasn't called. */
48+
perf_cpu_map__put(evsel->cpus);
49+
perf_cpu_map__put(evsel->own_cpus);
50+
perf_thread_map__put(evsel->threads);
4551
free(evsel);
4652
}
4753

0 commit comments

Comments
 (0)