The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: michael.niarchos@gmail.com
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] perf kvm: Fix memory leak in process_sample_event()
Date: Wed, 12 Aug 2026 16:41:50 +0900	[thread overview]
Message-ID: <anwjvuglUFEOld5F@google.com> (raw)
In-Reply-To: <20260807-perf-kvm-leaks-v1-1-7b5e2f97905a@gmail.com>

Hello,

On Fri, Aug 07, 2026 at 05:08:35PM +0200, Michalis Niarchos via B4 Relay wrote:
> From: Michalis Niarchos <michael.niarchos@gmail.com>
> 
> 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@gmail.com>
> ---
>  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
> 
> 

  reply	other threads:[~2026-08-12  7:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-07 15:08 [PATCH 0/2] perf kvm: Fix memory leaks Michalis Niarchos via B4 Relay
2026-08-07 15:08 ` [PATCH 1/2] perf kvm: Fix memory leak in process_sample_event() Michalis Niarchos via B4 Relay
2026-08-12  7:41   ` Namhyung Kim [this message]
2026-08-07 15:08 ` [PATCH 2/2] perf kvm: Fix memory leak in cmd_kvm() Michalis Niarchos via B4 Relay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=anwjvuglUFEOld5F@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=michael.niarchos@gmail.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox