Re: [PATCH] perf bench: futex: Fix memory leak of perf_cpu_map__new

From: Arnaldo Carvalho de Melo
Date: Sat Nov 13 2021 - 09:24:51 EST


Em Fri, Nov 12, 2021 at 10:11:33PM +0200, Sohaib Mohamed escreveu:
> 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: 9c3516d1b850 ("libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions")

Thanks, applied.

- Arnaldo


> Signed-off-by: Sohaib Mohamed <sohaib.amhmd@xxxxxxxxx>
> ---
> tools/perf/bench/futex-lock-pi.c | 1 +
> tools/perf/bench/futex-requeue.c | 1 +
> tools/perf/bench/futex-wake-parallel.c | 1 +
> tools/perf/bench/futex-wake.c | 1 +
> 4 files changed, 4 insertions(+)
>
> diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock-pi.c
> index 5d1fe9c35807..137890f78e17 100644
> --- a/tools/perf/bench/futex-lock-pi.c
> +++ b/tools/perf/bench/futex-lock-pi.c
> @@ -233,6 +233,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);
> diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c
> index 97fe31fd3a23..f7a5ffebb940 100644
> --- a/tools/perf/bench/futex-requeue.c
> +++ b/tools/perf/bench/futex-requeue.c
> @@ -294,6 +294,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);
> diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/futex-wake-parallel.c
> index e970e6b9ad53..0983f40b4b40 100644
> --- a/tools/perf/bench/futex-wake-parallel.c
> +++ b/tools/perf/bench/futex-wake-parallel.c
> @@ -329,6 +329,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 */
> diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c
> index 77f058a47790..2226a475e782 100644
> --- a/tools/perf/bench/futex-wake.c
> +++ b/tools/perf/bench/futex-wake.c
> @@ -222,5 +222,6 @@ int bench_futex_wake(int argc, const char **argv)
> print_summary();
>
> free(worker);
> + perf_cpu_map__put(cpu);
> return ret;
> }
> --
> 2.25.1

--

- Arnaldo