public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>,
	Namhyung Kim <namhyung@kernel.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>,
	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: Fri, 24 Nov 2023 13:56:35 +0100	[thread overview]
Message-ID: <ZWCdg5gcizJitxVw@gmail.com> (raw)
In-Reply-To: <20231124095319.GN3818@noisy.programming.kicks-ass.net>


* 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.

Thanks,

	Ingo

  reply	other threads:[~2023-11-24 12:56 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 [this message]
2023-11-27 13:18     ` Arnaldo Carvalho de Melo

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=ZWCdg5gcizJitxVw@gmail.com \
    --to=mingo@kernel.org \
    --cc=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@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