Re: [PATCH 06/20] perf dso: fix memory leak in dso__new_map
From: Arnaldo Carvalho de Melo
Date: Thu Jul 15 2021 - 16:02:15 EST
Em Thu, Jul 15, 2021 at 06:07:11PM +0200, Riccardo Mancini escreveu:
> 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.
Thanks, applied.
This needs some extra thinking for some unrelated issue, namely that
this dso isn't linked in the machine dso list, I think this is only used
by 'perf probe' :-\
I guess this won't be a problem since using the machine dso list is
important just for other tools, like when traversing to get the
build-ids, etc.
- Arnaldo
> 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
>
--
- Arnaldo