Re: [PATCH v7 2/5] perf cpumap: Add reference count checking

From: Arnaldo Carvalho de Melo
Date: Wed Apr 12 2023 - 13:45:16 EST


Em Tue, Apr 11, 2023 at 03:19:06PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Apr 07, 2023 at 04:04:02PM -0700, Ian Rogers escreveu:
> > This change is intended to catch:
> > - use after put: using a cpumap after you have put it will cause a
> > segv.
> > - unbalanced puts: two puts for a get will result in a double free
> > that can be captured and reported by tools like address sanitizer,
> > including with the associated stack traces of allocation and frees.
> > - missing puts: if a put is missing then the get turns into a memory
> > leak that can be reported by leak sanitizer, including the stack
> > trace at the point the get occurs.

> I think this should be further split into self contained patches as it
> does:
>
> 2. Exports perf_cpu_map__alloc() from libperf for use in tools/perf
>
> And its usage should be on a separate patch:
>
> > - struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);
> > + struct perf_cpu_map *cpus = perf_cpu_map__alloc(nr);