Messages in this thread | ![/](/images/icornerl.gif) | | From | Namhyung Kim <> | Date | Tue, 28 Dec 2021 15:54:56 -0800 | Subject | Re: [PATCH v2 22/48] perf cpumap: Trim the cpu_aggr_map |
| |
On Wed, Dec 22, 2021 at 11:47 PM Ian Rogers <irogers@google.com> wrote: > > cpu_aggr_map__new removes duplicates, when this happens shrink the > array. > > Reviewed-by: James Clark <james.clark@arm.com> > Signed-off-by: Ian Rogers <irogers@google.com> > --- > tools/perf/util/cpumap.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c > index 8a72ee996722..985c87f1f1ca 100644 > --- a/tools/perf/util/cpumap.c > +++ b/tools/perf/util/cpumap.c > @@ -185,7 +185,12 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, > c->nr++; > } > } > - > + /* Trim. */ > + if (c->nr != cpus->nr) { > + c = realloc(c, sizeof(struct cpu_aggr_map) + sizeof(struct aggr_cpu_id) * c->nr); > + if (!c) > + return NULL;
This leaks the original 'c'. Maybe we can just use it in case of a failure.
Thanks, Namhyung
> + } > /* ensure we process id in increasing order */ > qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); > > -- > 2.34.1.307.g9b7440fafd-goog >
| ![\](/images/icornerr.gif) |