From: Riccardo Mancini Date: Thu, 15 Jul 2021 16:07:11 +0000 (+0200) Subject: perf dso: Fix memory leak in dso__new_map() X-Git-Tag: v5.4.136~84 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d2bfc3eda914c8adaf0798b72439559f4da4f129;p=thirdparty%2Fkernel%2Fstable.git perf dso: Fix memory leak in dso__new_map() [ Upstream commit 581e295a0f6b5c2931d280259fbbfff56959faa9 ] ASan reports a memory leak when running: # perf test "65: maps__merge_in". The causes of the leaks are two, this patch addresses only the first one, which is related to dso__new_map(). The bug is that dso__new_map() creates a new dso but never decreases the refcount it gets from creating it. This patch adds the missing dso__put(). Signed-off-by: Riccardo Mancini Fixes: d3a7c489c7fd2463 ("perf tools: Reference count struct dso") Cc: Ian Rogers Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lore.kernel.org/lkml/60bfe0cd06e89e2ca33646eb8468d7f5de2ee597.1626343282.git.rickyman7@gmail.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index ab2e130dc07a6..7f07a5dc555f8 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -1086,8 +1086,10 @@ struct map *dso__new_map(const char *name) struct map *map = NULL; struct dso *dso = dso__new(name); - if (dso) + if (dso) { map = map__new2(0, dso); + dso__put(dso); + } return map; }