public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Kuan-Wei Chiu <visitorckw@gmail.com>, <yangyicong@hisilicon.com>,
	<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>,
	"Ian Rogers" <irogers@google.com>
Subject: Re: [PATCH] perf hisi-ptt: Fix memory leak in lseek failure handling
Date: Fri, 6 Oct 2023 09:09:59 +0100	[thread overview]
Message-ID: <20231006090959.00005787@Huawei.com> (raw)
In-Reply-To: <CAM9d7ciJZsCaVo6m_VtJ=QKNGAtBkAncidQjHzwexd3H8+3Usw@mail.gmail.com>

On Mon, 2 Oct 2023 21:48:14 -0700
Namhyung Kim <namhyung@kernel.org> wrote:

> Hello,
> 
> On Sat, Sep 30, 2023 at 12:27 AM Kuan-Wei Chiu <visitorckw@gmail.com> 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>  
> 
> Acked-by: Namhyung Kim <namhyung@kernel.org>
> 
FYI, Ian Rogers has a series with a similar fix that goes a little further
and drops the assignment of data_offset seen just at the top of the context
below as it is unused.

https://lore.kernel.org/all/20231005230851.3666908-5-irogers@google.com/

I haven't replied to this yet as want to check some related handling
with one of my China based colleagues and it's a festival this week.

One of us will get back on this next week,

Jonathan

> Thanks,
> Namhyung
> 
> 
> > ---
> >  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;
> > +               }
> >         }
> >
> >         err = readn(fd, data, size);
> > --
> > 2.25.1
> >  
> 


  reply	other threads:[~2023-10-06  8:10 UTC|newest]

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

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=20231006090959.00005787@Huawei.com \
    --to=jonathan.cameron@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=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