[PATCH 06/20] perf dso: fix memory leak in dso__new_map

From: Riccardo Mancini
Date: Thu Jul 15 2021 - 12:07:45 EST


ASan reports a memory leak when running the 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 <rickyman7@xxxxxxxxx>
---
tools/perf/util/dso.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index d786cf6b0cfa65f2..ee15db2be2f43403 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -1154,8 +1154,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;
}
--
2.31.1