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:47:18 +0000 (10:47 +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 30d97121dc4fb9352ef114cb7e5a0080a1721b10..c54013806ba4a27263d4103addb8ecac8a89336a 100644 (file)
@@ -224,6 +224,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 a00a6891447ab3dcf3595f82b5526c6cea64ee7c..11b7dbd374864b6c36f266a9807dcc4d3f6436bf 100644 (file)
@@ -215,6 +215,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 a053cf2b703974353ce0456e5c1e2a3a5b454259..c3033d0905db154de7b0fa47a64211555bcb22d5 100644 (file)
@@ -319,6 +319,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 58906e9499bb0c5935644f1f52f93bfd35694bb0..ad44a78392dc4530865f983ff67770ca56f37ecf 100644 (file)
@@ -209,5 +209,6 @@ int bench_futex_wake(int argc, const char **argv)
        print_summary();
 
        free(worker);
+       perf_cpu_map__put(cpu);
        return ret;
 }