Skip to content

Commit 9ef3026

Browse files
namhyungacmel
authored andcommitted
perf annotate: Fix segfault on sample histogram
A symbol can have no samples, then accessing the annotated_source->samples hashmap will result in a segfault. Fixes: a3f7768 ("perf annotate: Fix memory leak in annotated_source") Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20240510210452.2449944-1-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0954160 commit 9ef3026

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/perf/util/annotate.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ static __maybe_unused void annotated_source__delete(struct annotated_source *src
113113
if (src == NULL)
114114
return;
115115

116-
hashmap__for_each_entry(src->samples, cur, bkt)
117-
zfree(&cur->pvalue);
118-
119-
hashmap__free(src->samples);
116+
if (src->samples) {
117+
hashmap__for_each_entry(src->samples, cur, bkt)
118+
zfree(&cur->pvalue);
119+
hashmap__free(src->samples);
120+
}
120121
zfree(&src->histograms);
121122
free(src);
122123
}

0 commit comments

Comments
 (0)