All of lore.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: sashiko-reviews@lists.linux.dev
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v1 1/3] perf sched: Add missing perf_session__delete()
Date: Mon, 13 Jul 2026 16:00:15 -0700	[thread overview]
Message-ID: <alVt_4Oaj8SvqAlv@google.com> (raw)
In-Reply-To: <20260713205907.77D4F1F000E9@smtp.kernel.org>

On Mon, Jul 13, 2026 at 08:59:07PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The patch introduces a double close of the file descriptor `fd` because `perf_session__delete(session)` inherently closes it before the explicit `close(fd)`.
> --
> 
> --- Patch [1]: [PATCH v1 1/3] perf sched: Add missing perf_session__delete() ---
> commit 2da9bd6a7ce8e17e442d8be81b1b57837aaee6e1
> Author: Namhyung Kim <namhyung@kernel.org>
> 
> perf sched: Add missing perf_session__delete()
> 
> This patch addresses an ASAN-reported memory leak in the perf sched stats
> record command by explicitly deleting the session before returning.
> 
> > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> > index 6e0d8f4d270e2..68147a0be5c71 100644
> > --- a/tools/perf/builtin-sched.c
> > +++ b/tools/perf/builtin-sched.c
> > @@ -4027,6 +4027,7 @@ static int perf_sched__schedstat_record(struct perf_sched *sched,
> >  	else
> >  		fprintf(stderr, "[ perf sched stats: Failed !! ]\n");
> >  
> > +	perf_session__delete(session);
> >  	evlist__put(evlist);
> >  	close(fd);
> 
> [Severity: Medium]
> Does adding perf_session__delete() result in closing the file descriptor twice?
> 
> Since perf_session__delete() internally closes the file descriptor associated
> with the session data, the subsequent explicit close(fd) will attempt to
> close it again. This could return EBADF or erroneously close an unrelated
> file descriptor if another thread opens a file in the meantime.

Hmm.. looks right.  I think I can just remove the close().

Thanks,
Namhyung


  reply	other threads:[~2026-07-13 23:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 20:47 [PATCH v1 0/3] perf sched stats: Fix memory leaks Namhyung Kim
2026-07-13 20:47 ` [PATCH v1 1/3] perf sched: Add missing perf_session__delete() Namhyung Kim
2026-07-13 20:59   ` sashiko-bot
2026-07-13 23:00     ` Namhyung Kim [this message]
2026-07-13 20:47 ` [PATCH v1 2/3] perf sched: Fix memory leaks in perf sched stats report Namhyung Kim
2026-07-13 20:47 ` [PATCH v1 3/3] perf sched: Free subcommand string after perf sched stats Namhyung Kim

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=alVt_4Oaj8SvqAlv@google.com \
    --to=namhyung@kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.