Commit 6f47ed6c authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf metric: Do not free metric when failed to resolve

It's dangerous to free the original metric when it's called from
resolve_metric() as it's already in the metric_list and might have other
resources too.  Instead, it'd better let them bail out and be released
properly at the later stage.

So add a check when it's called from metricgroup__add_metric() and
release it.  Also make sure that mp is set properly.

Fixes: 83de0b7d ("perf metric: Collect referenced metrics in struct metric_ref_node")
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200915031819.386559-10-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 27adafcd
...@@ -672,7 +672,6 @@ static int __add_metric(struct list_head *metric_list, ...@@ -672,7 +672,6 @@ static int __add_metric(struct list_head *metric_list,
m->has_constraint = metric_no_group || metricgroup__has_constraint(pe); m->has_constraint = metric_no_group || metricgroup__has_constraint(pe);
INIT_LIST_HEAD(&m->metric_refs); INIT_LIST_HEAD(&m->metric_refs);
m->metric_refs_cnt = 0; m->metric_refs_cnt = 0;
*mp = m;
parent = expr_ids__alloc(ids); parent = expr_ids__alloc(ids);
if (!parent) { if (!parent) {
...@@ -685,6 +684,7 @@ static int __add_metric(struct list_head *metric_list, ...@@ -685,6 +684,7 @@ static int __add_metric(struct list_head *metric_list,
free(m); free(m);
return -ENOMEM; return -ENOMEM;
} }
*mp = m;
} else { } else {
/* /*
* We got here for the referenced metric, via the * We got here for the referenced metric, via the
...@@ -719,8 +719,11 @@ static int __add_metric(struct list_head *metric_list, ...@@ -719,8 +719,11 @@ static int __add_metric(struct list_head *metric_list,
* all the metric's IDs and add it to the parent context. * all the metric's IDs and add it to the parent context.
*/ */
if (expr__find_other(pe->metric_expr, NULL, &m->pctx, runtime) < 0) { if (expr__find_other(pe->metric_expr, NULL, &m->pctx, runtime) < 0) {
expr__ctx_clear(&m->pctx); if (m->metric_refs_cnt == 0) {
free(m); expr__ctx_clear(&m->pctx);
free(m);
*mp = NULL;
}
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment