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

From: Arnaldo Carvalho de Melo
Date: Thu Jul 15 2021 - 16:07:31 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.

Fixes: d3a7c489c7fd2463 ("perf tools: Reference count struct dso")

Thanks, applied.

- 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