From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
zhaimingbing <zhaimingbing@cmss.chinamobile.com>,
Namhyung Kim <namhyung@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
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>,
Sean Christopherson <seanjc@google.com>,
Li Dong <lidong@vivo.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf lock: Fix a memory leak on an error path
Date: Mon, 27 Nov 2023 10:18:03 -0300 [thread overview]
Message-ID: <ZWSXCwrx5BUpYGi/@kernel.org> (raw)
In-Reply-To: <ZWCdg5gcizJitxVw@gmail.com>
Em Fri, Nov 24, 2023 at 01:56:35PM +0100, Ingo Molnar escreveu:
>
> * Peter Zijlstra <peterz@infradead.org> wrote:
>
> > On Fri, Nov 24, 2023 at 05:26:57PM +0800, zhaimingbing wrote:
> > > if a strdup-ed string is NULL,the allocated memory needs freeing.
> > >
> > > Signed-off-by: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
> > > ---
> > > tools/perf/builtin-lock.c | 4 +++-
> > > 1 file changed, 3 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> > > index b141f2134..086041bcb 100644
> > > --- a/tools/perf/builtin-lock.c
> > > +++ b/tools/perf/builtin-lock.c
> > > @@ -2228,8 +2228,10 @@ static int __cmd_record(int argc, const char **argv)
> > > else
> > > ev_name = strdup(contention_tracepoints[j].name);
> > >
> > > - if (!ev_name)
> > > + if (!ev_name) {
> > > + free(rec_argv);
> > > return -ENOMEM;
> > > + }
> >
> > Isn't this an error path straight into exit?
>
> It increases the quality of implementation if resources are free()d
> consistently regardless of whether the task is going to exit() immediately,
> for example it makes it easier to validate perf for the lack of memory
> leaks with Valgrind.
I'm taking this positive comment about the patch as an Acked-by, ok?
- Arnaldo
prev parent reply other threads:[~2023-11-27 13:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-24 9:26 [PATCH] perf lock: Fix a memory leak on an error path zhaimingbing
2023-11-24 9:53 ` Peter Zijlstra
2023-11-24 12:56 ` Ingo Molnar
2023-11-27 13:18 ` Arnaldo Carvalho de Melo [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=ZWSXCwrx5BUpYGi/@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=lidong@vivo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=zhaimingbing@cmss.chinamobile.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;
as well as URLs for NNTP newsgroup(s).