perf metricgroup: Fix use after free in metric__new()
authorJosé Expósito <jose.exposito89@gmail.com>
Wed, 8 Dec 2021 17:11:13 +0000 (18:11 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 11:03:00 +0000 (12:03 +0100)
commit e000ea0beffb5497425054b151369fe37a792ece upstream.

We shouldn't free() something that will be used in the next line, fix
it.

Fixes: b85a4d61d3022608 ("perf metric: Allow modifiers on metrics")
Addresses-Coverity-ID: 1494000
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20211208171113.22089-1-jose.exposito89@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/perf/util/metricgroup.c

index fffe02aae3ed1fa538da9400753218d2be37c232..4d2fed3aefd173503552f64c13389b968ba5d846 100644 (file)
@@ -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;