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

perf test: Fix memory leaks in parse-metric test

It didn't release resources when there's an error so the
test_recursion_fail() will leak some memory.

Fixes: 0a507af9 ("perf tests: Add parse metric test for ipc metric")
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-7-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b12eea5a
...@@ -153,8 +153,10 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -153,8 +153,10 @@ static int __compute_metric(const char *name, struct value *vals,
return -ENOMEM; return -ENOMEM;
cpus = perf_cpu_map__new("0"); cpus = perf_cpu_map__new("0");
if (!cpus) if (!cpus) {
evlist__delete(evlist);
return -ENOMEM; return -ENOMEM;
}
perf_evlist__set_maps(&evlist->core, cpus, NULL); perf_evlist__set_maps(&evlist->core, cpus, NULL);
...@@ -163,10 +165,11 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -163,10 +165,11 @@ static int __compute_metric(const char *name, struct value *vals,
false, false, false, false,
&metric_events); &metric_events);
if (err) if (err)
return err; goto out;
if (perf_evlist__alloc_stats(evlist, false)) err = perf_evlist__alloc_stats(evlist, false);
return -1; if (err)
goto out;
/* Load the runtime stats with given numbers for events. */ /* Load the runtime stats with given numbers for events. */
runtime_stat__init(&st); runtime_stat__init(&st);
...@@ -178,13 +181,14 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -178,13 +181,14 @@ static int __compute_metric(const char *name, struct value *vals,
if (name2 && ratio2) if (name2 && ratio2)
*ratio2 = compute_single(&metric_events, evlist, &st, name2); *ratio2 = compute_single(&metric_events, evlist, &st, name2);
out:
/* ... clenup. */ /* ... clenup. */
metricgroup__rblist_exit(&metric_events); metricgroup__rblist_exit(&metric_events);
runtime_stat__exit(&st); runtime_stat__exit(&st);
perf_evlist__free_stats(evlist); perf_evlist__free_stats(evlist);
perf_cpu_map__put(cpus); perf_cpu_map__put(cpus);
evlist__delete(evlist); evlist__delete(evlist);
return 0; return err;
} }
static int compute_metric(const char *name, struct value *vals, double *ratio) static int compute_metric(const char *name, struct value *vals, double *ratio)
......
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