Re: [PATCH] perf util: Fix use after free in metric__new

Arnaldo Carvalho de Melo
2022-01-14T14:46:05Z

Em Wed, Dec 08, 2021 at 06:11:13PM +0100, José Expósito escreveu:
> Addresses-Coverity-ID: 1494000
> Signed-off-by: José Expósito <jose.exposito89@gmail.com>

Sorry, overlooked this one, now processing.

You forgot to add:

Fixes: b85a4d61d3022608 ("perf metric: Allow modifiers on metrics")

Ian, I'm taking this one, obvious fix.

- Arnaldo

> ---
> tools/perf/util/metricgroup.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index fffe02aae3ed..4d2fed3aefd1 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -209,8 +209,8 @@ static struct metric *metric__new(const struct pmu_event *pe,
> m->metric_name = pe->metric_name;
> m->modifier = modifier ? strdup(modifier) : NULL;
> if (modifier && !m->modifier) {
> - free(m);
> expr__ctx_free(m->pctx);
> + free(m);
> return NULL;
> }
> m->metric_expr = pe->metric_expr;
> --
> 2.25.1

--

- Arnaldo