summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2025-06-17 15:33:56 -0700
committerNamhyung Kim <namhyung@kernel.org>2025-06-24 10:27:51 -0700
commitbe59dba332e1e8edd3e88d991ba0e4795ae2bcb2 (patch)
tree600416de450b5b00d939a8fee95f1098449fc626
parenteda9e47fae276d2b7a2b6a826b38259e6481d879 (diff)
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 <irogers@google.com> Link: https://lore.kernel.org/r/20250617223356.2752099-4-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
-rw-r--r--tools/lib/perf/evsel.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index c475319e2e41..2a85e0bfee1e 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -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);
}