public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
Cc: 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 10:53:19 +0100	[thread overview]
Message-ID: <20231124095319.GN3818@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20231124092657.10392-1-zhaimingbing@cmss.chinamobile.com>

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?

  reply	other threads:[~2023-11-24  9: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 [this message]
2023-11-24 12:56   ` Ingo Molnar
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=20231124095319.GN3818@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.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=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