Re: [PATCH] perf map: Fix refcount errors on Arm with -DREFCNT_CHECKING=1

From: Arnaldo Carvalho de Melo
Date: Mon Jun 12 2023 - 13:41:07 EST


Em Mon, Jun 12, 2023 at 02:29:42PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Mon, Jun 12, 2023 at 09:32:30AM -0700, Ian Rogers escreveu:
> > On Mon, Jun 12, 2023 at 8:05 AM James Clark <james.clark@xxxxxxx> wrote:
> > >
> > > When quitting after running a perf report, the refcount checker finds
> > > some double frees. The issue is that map__put() is called on a function
> > > argument so it removes the refcount wrapper that someone else was using.
> > >
> > > Fix it by only calling map__put() on a reference that is owned by this
> > > function.
> > >
> > > Signed-off-by: James Clark <james.clark@xxxxxxx>
> >
> > Acked-by: Ian Rogers <irogers@xxxxxxxxxx>
> >
> > > ---
> > > tools/perf/util/symbol-elf.c | 9 +++++----
> > > tools/perf/util/symbol.c | 9 +++++----
> > > 2 files changed, 10 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> > > index 63882a4db5c7..ec0d7810bbb0 100644
> > > --- a/tools/perf/util/symbol-elf.c
> > > +++ b/tools/perf/util/symbol-elf.c
> > > @@ -1365,6 +1365,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
> > > struct dso *curr_dso = *curr_dsop;
> > > struct map *curr_map;
> > > char dso_name[PATH_MAX];
> > > + struct map *map_ref;
> >
> > nit: can we narrow the scope of this by moving it to the scope where it is used.
>
> Which is what you did in a patch I already processed, its only in
> tmp.perf-tools-next as I was going thru the other patches, but this one
> is there already.
>
> I'm checking the tools/perf/util/symbol.c part.

I narrowed the scope and removed the symbol-elf.c part, end result: