[PATCH v2 26/26] perf hist: Fix srcline memory leak

From: Ian Rogers
Date: Thu Jun 08 2023 - 19:32:01 EST


srcline isn't freed if it is SRCLINE_UNKNOWN. Avoid strduping in this
case as such strdups are redundant and leak memory.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/hist.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 77cb2cc83bb9..cc6f7f51faa5 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -484,7 +484,7 @@ static int hist_entry__init(struct hist_entry *he,
goto err_infos;
}

- if (he->srcline) {
+ if (he->srcline && strcmp(he->srcline, SRCLINE_UNKNOWN)) {
he->srcline = strdup(he->srcline);
if (he->srcline == NULL)
goto err_rawdata;
--
2.41.0.162.gfafddb0af9-goog