[PATCH v1 2/8] perf annotate: Fix memory leak in annotated_source

From: Ian Rogers
Date: Tue May 07 2024 - 14:36:37 EST


Freeing hash map doesn't free the entries added to the hashmap, add
missing free.

Fixes: d3e7cad6f36d ("perf annotate: Add a hashmap for symbol histogram")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/annotate.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index d7d55263fc91..a83722f32d6b 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -107,9 +107,15 @@ static struct annotated_source *annotated_source__new(void)

static __maybe_unused void annotated_source__delete(struct annotated_source *src)
{
+ struct hashmap_entry *cur;
+ size_t bkt;
+
if (src == NULL)
return;

+ hashmap__for_each_entry(src->samples, cur, bkt)
+ zfree(&cur->pvalue);
+
hashmap__free(src->samples);
zfree(&src->histograms);
free(src);
--
2.45.0.rc1.225.g2a3ae87e7f-goog