After CPU maps are merged, the old CPU map will not automatically
released.
This commit adds a new variable to record old CPU map, after merging the
new allocated map is returned, and release the old CPU map.
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/lib/perf/evlist.c | 4 ++++
tools/perf/util/mem-events.c | 4 +++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c
index c6d67fc9e57e..37920e0b0cd6 100644
--- a/tools/lib/perf/evlist.c
+++ b/tools/lib/perf/evlist.c
@@ -36,6 +36,8 @@ void perf_evlist__init(struct perf_evlist *evlist)
static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
struct perf_evsel *evsel)
{
+ struct perf_cpu_map *old_all_cpus;
+
if (evsel->system_wide) {
/* System wide: set the cpu map of the evsel to all online CPUs. */
perf_cpu_map__put(evsel->cpus);
@@ -75,7 +77,9 @@ static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
evsel->threads = perf_thread_map__get(evlist->threads);
}
+ old_all_cpus = evlist->all_cpus;
evlist->all_cpus = perf_cpu_map__merge(evlist->all_cpus, evsel->cpus);
+ perf_cpu_map__put(old_all_cpus);
}
static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 051feb93ed8d..016a1f4adb5d 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -257,7 +257,7 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr)
int i = *argv_nr;
const char *s;
char *copy;
- struct perf_cpu_map *cpu_map = NULL;
+ struct perf_cpu_map *cpu_map = NULL, *old_cpu_map;
while ((pmu = perf_pmus__scan_mem(pmu)) != NULL) {
for (int j = 0; j < PERF_MEM_EVENTS__MAX; j++) {
@@ -283,7 +283,9 @@ int perf_mem_events__record_args(const char **rec_argv, int *argv_nr)
rec_argv[i++] = "-e";
rec_argv[i++] = copy;
+ old_cpu_map = cpu_map;
cpu_map = perf_cpu_map__merge(cpu_map, pmu->cpus);
+ perf_cpu_map__put(old_cpu_map);
}
}
--
2.34.1