Skip to content

Commit f5a5657

Browse files
namhyungacmel
authored andcommitted
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: 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]>
1 parent b12eea5 commit f5a5657

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/perf/tests/parse-metric.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ static int __compute_metric(const char *name, struct value *vals,
153153
return -ENOMEM;
154154

155155
cpus = perf_cpu_map__new("0");
156-
if (!cpus)
156+
if (!cpus) {
157+
evlist__delete(evlist);
157158
return -ENOMEM;
159+
}
158160

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

@@ -163,10 +165,11 @@ static int __compute_metric(const char *name, struct value *vals,
163165
false, false,
164166
&metric_events);
165167
if (err)
166-
return err;
168+
goto out;
167169

168-
if (perf_evlist__alloc_stats(evlist, false))
169-
return -1;
170+
err = perf_evlist__alloc_stats(evlist, false);
171+
if (err)
172+
goto out;
170173

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

184+
out:
181185
/* ... clenup. */
182186
metricgroup__rblist_exit(&metric_events);
183187
runtime_stat__exit(&st);
184188
perf_evlist__free_stats(evlist);
185189
perf_cpu_map__put(cpus);
186190
evlist__delete(evlist);
187-
return 0;
191+
return err;
188192
}
189193

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

0 commit comments

Comments
 (0)