Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 0a507af9c681a ("perf tests: Add parse metric test for ipc metric")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri 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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
f5a56570 b12eea5a

+9 -5
+9 -5
tools/perf/tests/parse-metric.c
··· 153 153 return -ENOMEM; 154 154 155 155 cpus = perf_cpu_map__new("0"); 156 - if (!cpus) 156 + if (!cpus) { 157 + evlist__delete(evlist); 157 158 return -ENOMEM; 159 + } 158 160 159 161 perf_evlist__set_maps(&evlist->core, cpus, NULL); 160 162 ··· 165 163 false, false, 166 164 &metric_events); 167 165 if (err) 168 - return err; 166 + goto out; 169 167 170 - if (perf_evlist__alloc_stats(evlist, false)) 171 - return -1; 168 + err = perf_evlist__alloc_stats(evlist, false); 169 + if (err) 170 + goto out; 172 171 173 172 /* Load the runtime stats with given numbers for events. */ 174 173 runtime_stat__init(&st); ··· 181 178 if (name2 && ratio2) 182 179 *ratio2 = compute_single(&metric_events, evlist, &st, name2); 183 180 181 + out: 184 182 /* ... clenup. */ 185 183 metricgroup__rblist_exit(&metric_events); 186 184 runtime_stat__exit(&st); 187 185 perf_evlist__free_stats(evlist); 188 186 perf_cpu_map__put(cpus); 189 187 evlist__delete(evlist); 190 - return 0; 188 + return err; 191 189 } 192 190 193 191 static int compute_metric(const char *name, struct value *vals, double *ratio)