Re: [PATCH 1/2] perf kvm: Fix memory leak in process_sample_event()
From: Namhyung Kim
Date: Wed Aug 12 2026 - 03:42:43 EST
Hello,
On Fri, Aug 07, 2026 at 05:08:35PM +0200, Michalis Niarchos via B4 Relay wrote:
> From: Michalis Niarchos <michael.niarchos@xxxxxxxxx>
>
> machine__resolve() indirectly acquires a thread reference via
> machine__findnew_thread(). Release it, as suggested by the documentation
> of the former.
>
> Signed-off-by: Michalis Niarchos <michael.niarchos@xxxxxxxxx>
> ---
> tools/perf/builtin-kvm.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
> index 00baafb05603..8e7bc7b2db18 100644
> --- a/tools/perf/builtin-kvm.c
> +++ b/tools/perf/builtin-kvm.c
> @@ -1145,7 +1145,7 @@ static int process_sample_event(const struct perf_tool *tool,
> if (machine__resolve(machine, &kvm->al, sample) < 0) {
> pr_warning("WARNING: at offset %#" PRIx64 ": fail to resolve address location, skipping sample\n",
> sample->file_offset);
> - return 0;
> + goto out;
I think it's ok to return here when machine__resolve() returns -1.
I'll remove this hunk.
Thanks,
Namhyung
> }
>
> thread = machine__findnew_thread(machine, sample->pid, sample->tid);
> @@ -1153,13 +1153,16 @@ static int process_sample_event(const struct perf_tool *tool,
> pr_debug("problem processing %s (%u) event at offset %#" PRIx64 ", skipping it.\n",
> perf_event__name(event->header.type), event->header.type,
> sample->file_offset);
> - return -1;
> + err = -1;
> + goto out;
> }
>
> if (!handle_kvm_event(kvm, thread, sample))
> err = -1;
>
> thread__put(thread);
> +out:
> + addr_location__exit(&kvm->al);
> return err;
> }
>
>
> --
> 2.55.0
>
>