Commit be59dba3 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

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: default avatarIan Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250617223356.2752099-4-irogers@google.com


Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent eda9e47f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -42,6 +42,12 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)

void perf_evsel__delete(struct perf_evsel *evsel)
{
	assert(evsel->fd == NULL);  /* If not fds were not closed. */
	assert(evsel->mmap == NULL); /* If not munmap wasn't called. */
	assert(evsel->sample_id == NULL); /* If not free_id wasn't called. */
	perf_cpu_map__put(evsel->cpus);
	perf_cpu_map__put(evsel->own_cpus);
	perf_thread_map__put(evsel->threads);
	free(evsel);
}