mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yicong Yang <yangyicong@huawei.com>
To: Kuan-Wei Chiu <visitorckw@gmail.com>, <yangyicong@hisilicon.com>,
	<jonathan.cameron@huawei.com>, <namhyung@kernel.org>
Cc: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<jolsa@kernel.org>, <irogers@google.com>,
	<adrian.hunter@intel.com>, <linux-kernel@vger.kernel.org>,
	<linux-perf-users@vger.kernel.org>
Subject: Re: [PATCH] perf hisi-ptt: Fix memory leak in lseek failure handling
Date: Mon, 9 Oct 2023 22:53:57 +0800	[thread overview]
Message-ID: <7e27ac27-c53e-0039-d195-5cd787d9df43@huawei.com> (raw)
In-Reply-To: <20230930072719.1267784-1-visitorckw@gmail.com>

On 2023/9/30 15:27, Kuan-Wei Chiu wrote:
> In the previous code, there was a memory leak issue where the previously
> allocated memory was not freed upon a failed lseek operation. This patch
> addresses the problem by releasing the old memory before returning -errno
> in case of a lseek failure. This ensures that memory is properly managed
> and avoids potential memory leaks.
> 
> Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
> ---
>  tools/perf/util/hisi-ptt.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/hisi-ptt.c b/tools/perf/util/hisi-ptt.c
> index 45b614bb73bf..43bd1ca62d58 100644
> --- a/tools/perf/util/hisi-ptt.c
> +++ b/tools/perf/util/hisi-ptt.c
> @@ -108,8 +108,10 @@ static int hisi_ptt_process_auxtrace_event(struct perf_session *session,
>  		data_offset = 0;
>  	} else {
>  		data_offset = lseek(fd, 0, SEEK_CUR);
> -		if (data_offset == -1)
> +		if (data_offset == -1) {
> +			free(data);
>  			return -errno;
> +		}

Sorry for the late reply, this looks correct to me:

Acked-by: Yicong Yang <yangyicong@hisilicon.com>

This patch makes me think whether data_offset is necessary for PTT.
The PTT only supports dump raw trace data and since this is an
uncore PMU we only have one single data source so we are not using
the auxtrace_queues for sorting or ordering the buffers. It seems
there's no need to record the data_offset for later mmap(),
just read trace data out and dump them is enough. I'll further check
and have some tests on this.

I see Namhyung has already taken this. Thanks for the fix.

>  	}
>  
>  	err = readn(fd, data, size);
> 

      parent reply	other threads:[~2023-10-09 14:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30  7:27 Kuan-Wei Chiu
2023-10-03  4:48 ` Namhyung Kim
2023-10-06  8:09   ` Jonathan Cameron
2023-10-09  5:21   ` Namhyung Kim
2023-10-09 14:53 ` Yicong Yang [this message]

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=7e27ac27-c53e-0039-d195-5cd787d9df43@huawei.com \
    --to=yangyicong@huawei.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=visitorckw@gmail.com \
    --cc=yangyicong@hisilicon.com \
    /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

all inboxes | Powered by JetHome®