[PATCH 2/8] perf sched: Free thread->priv using priv_destructor

Namhyung Kim posted 8 patches 3 months, 1 week ago
[PATCH 2/8] perf sched: Free thread->priv using priv_destructor
Posted by Namhyung Kim 3 months, 1 week ago
In many perf sched subcommand saves priv data structure in the thread
but it forgot to free them.  As it's an opaque type with 'void *', it
needs to register that knows how to free the data.  In this case, just
regular 'free()' is fine.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/builtin-sched.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index b7bbfad0ed600eee..fa4052e040201105 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -3898,6 +3898,8 @@ int cmd_sched(int argc, const char **argv)
 	if (!argc)
 		usage_with_options(sched_usage, sched_options);
 
+	thread__set_priv_destructor(free);
+
 	/*
 	 * Aliased to 'perf script' for now:
 	 */
-- 
2.50.0.727.gbf7dc18ff4-goog
Re: [PATCH 2/8] perf sched: Free thread->priv using priv_destructor
Posted by Ian Rogers 3 months ago
On Wed, Jul 2, 2025 at 6:49 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> In many perf sched subcommand saves priv data structure in the thread
> but it forgot to free them.  As it's an opaque type with 'void *', it
> needs to register that knows how to free the data.  In this case, just
> regular 'free()' is fine.
>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian

> ---
>  tools/perf/builtin-sched.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index b7bbfad0ed600eee..fa4052e040201105 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -3898,6 +3898,8 @@ int cmd_sched(int argc, const char **argv)
>         if (!argc)
>                 usage_with_options(sched_usage, sched_options);
>
> +       thread__set_priv_destructor(free);
> +
>         /*
>          * Aliased to 'perf script' for now:
>          */
> --
> 2.50.0.727.gbf7dc18ff4-goog
>