Skip to content

Commit

Permalink
perf test: Fix memory leaks in parse-metric test
Browse files Browse the repository at this point in the history
It didn't release resources when there's an error so the
test_recursion_fail() will leak some memory.

Fixes: 0a507af ("perf tests: Add parse metric test for ipc metric")
Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
namhyung authored and acmel committed Sep 15, 2020
1 parent b12eea5 commit f5a5657
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions tools/perf/tests/parse-metric.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ static int __compute_metric(const char *name, struct value *vals,
return -ENOMEM;

cpus = perf_cpu_map__new("0");
if (!cpus)
if (!cpus) {
evlist__delete(evlist);
return -ENOMEM;
}

perf_evlist__set_maps(&evlist->core, cpus, NULL);

Expand All @@ -163,10 +165,11 @@ static int __compute_metric(const char *name, struct value *vals,
false, false,
&metric_events);
if (err)
return err;
goto out;

if (perf_evlist__alloc_stats(evlist, false))
return -1;
err = perf_evlist__alloc_stats(evlist, false);
if (err)
goto out;

/* Load the runtime stats with given numbers for events. */
runtime_stat__init(&st);
Expand All @@ -178,13 +181,14 @@ static int __compute_metric(const char *name, struct value *vals,
if (name2 && ratio2)
*ratio2 = compute_single(&metric_events, evlist, &st, name2);

out:
/* ... clenup. */
metricgroup__rblist_exit(&metric_events);
runtime_stat__exit(&st);
perf_evlist__free_stats(evlist);
perf_cpu_map__put(cpus);
evlist__delete(evlist);
return 0;
return err;
}

static int compute_metric(const char *name, struct value *vals, double *ratio)
Expand Down

0 comments on commit f5a5657

Please sign in to comment.