kernel/patches/0256-perf-test-Fix-memory-leaks-in-parse-metric-test.patch
2023-11-10 14:47:39 +08:00

88 lines
2.8 KiB
Diff

From e620e326e3e9f742aab5d960b61e1c24108ec909 Mon Sep 17 00:00:00 2001
From: Namhyung Kim <namhyung@kernel.org>
Date: Tue, 15 Sep 2020 12:18:14 +0900
Subject: [PATCH 139/201] perf test: Fix memory leaks in parse-metric test
mainline inclusion
from mainline-v5.9-rc6
commit f5a56570a3f2c01e5307a972ae7d4636edff7b13
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I8C0CX
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f5a56570a3f2c01e5307a972ae7d4636edff7b13
----------------------------------------------------------------------
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>
Signed-off-by: hongrongxuan <hongrongxuan@huawei.com>
Conflicts:
tools/perf/tests/parse-metric.c
---
tools/perf/tests/parse-metric.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c
index 007da421bf95..936953991347 100644
--- a/tools/perf/tests/parse-metric.c
+++ b/tools/perf/tests/parse-metric.c
@@ -148,8 +148,10 @@ static int __compute_metric(const char *name, struct value *vals,
return -ENOMEM;
cpus = cpu_map__new("0");
- if (!cpus)
+ if (!cpus) {
+ perf_evlist__delete(evlist);
return -ENOMEM;
+ }
perf_evlist__set_maps(evlist, cpus, NULL);
@@ -158,10 +160,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);
@@ -173,13 +176,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);
cpu_map__put(cpus);
perf_evlist__delete(evlist);
- return 0;
+ return err;
}
static int compute_metric(const char *name, struct value *vals, double *ratio)
--
2.27.0