perf bench futex: Fix memory leak of perf_cpu_map__new()
authorSohaib Mohamed <sohaib.amhmd@gmail.com>
Fri, 12 Nov 2021 20:11:33 +0000 (22:11 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Nov 2021 09:39:13 +0000 (10:39 +0100)
[ Upstream commit 88e48238d53682281c9de2a0b65d24d3b64542a0 ]

ASan reports memory leaks while running:

  $ sudo ./perf bench futex all

The leaks are caused by perf_cpu_map__new not being freed.
This patch adds the missing perf_cpu_map__put since it calls
cpu_map_delete implicitly.

Fixes: 9c3516d1b850ea93 ("libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions")
Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: André Almeida <andrealmeid@collabora.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lore.kernel.org/lkml/20211112201134.77892-1-sohaib.amhmd@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/perf/bench/futex-lock-pi.c
tools/perf/bench/futex-requeue.c
tools/perf/bench/futex-wake-parallel.c
tools/perf/bench/futex-wake.c

index bb25d8beb3b852f71def15136fcc5f22de816aca..159bc89e6a79a2c15a0762a8cb91644664909bad 100644 (file)
@@ -226,6 +226,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
        print_summary();
 
        free(worker);
+       perf_cpu_map__put(cpu);
        return ret;
 err:
        usage_with_options(bench_futex_lock_pi_usage, options);
index 7a15c2e610228f081d8a3e5b8da2e5e283a8a427..105b36cdc42d310dfbbc71e1528a323ead00f937 100644 (file)
@@ -216,6 +216,7 @@ int bench_futex_requeue(int argc, const char **argv)
        print_summary();
 
        free(worker);
+       perf_cpu_map__put(cpu);
        return ret;
 err:
        usage_with_options(bench_futex_requeue_usage, options);
index cd2b81a845acb0537f8841fb914b006c69c17772..a129c94eb3fe1a2ccddf0be4d5d26e9e875b952c 100644 (file)
@@ -320,6 +320,7 @@ int bench_futex_wake_parallel(int argc, const char **argv)
        print_summary();
 
        free(blocked_worker);
+       perf_cpu_map__put(cpu);
        return ret;
 }
 #endif /* HAVE_PTHREAD_BARRIER */
index 2dfcef3e371e4b15b9dead17bfa348b00e2a79d1..507ff533612c684f4d0dc387a0b0334eec0f0158 100644 (file)
@@ -210,5 +210,6 @@ int bench_futex_wake(int argc, const char **argv)
        print_summary();
 
        free(worker);
+       perf_cpu_map__put(cpu);
        return ret;
 }