Skip to content

Commit

Permalink
perf metricgroup: Fix use after free in metric__new()
Browse files Browse the repository at this point in the history
We shouldn't free() something that will be used in the next line, fix
it.

Fixes: b85a4d6 ("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>
  • Loading branch information
José Expósito authored and Arnaldo Carvalho de Melo committed Jan 14, 2022
1 parent 99fc11b commit e000ea0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/perf/util/metricgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e000ea0

Please sign in to comment.