Skip to content

Commit

Permalink
perf annotate: Fix segfault on sample histogram
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed May 11, 2024
1 parent 0954160 commit 9ef3026
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tools/perf/util/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ static __maybe_unused void annotated_source__delete(struct annotated_source *src
if (src == NULL)
return;

hashmap__for_each_entry(src->samples, cur, bkt)
zfree(&cur->pvalue);

hashmap__free(src->samples);
if (src->samples) {
hashmap__for_each_entry(src->samples, cur, bkt)
zfree(&cur->pvalue);
hashmap__free(src->samples);
}
zfree(&src->histograms);
free(src);
}
Expand Down

0 comments on commit 9ef3026

Please sign in to comment.