mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Felipe Pena <felipensp@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@ghostprotocols.net>,
	Borislav Petkov <bp@suse.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] tools/perf/util: Fix memory leak in trace-event-info.c
Date: Mon, 14 Oct 2013 14:07:09 +0900	[thread overview]
Message-ID: <87fvs4bfuq.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: <1381454489-4135-1-git-send-email-felipensp@gmail.com> (Felipe Pena's message of "Thu, 10 Oct 2013 22:21:29 -0300")

Hi Felipe,

On Thu, 10 Oct 2013 22:21:29 -0300, Felipe Pena wrote:
> Fix for a memory leak on tracing_data_get() function when returning NULL explicitly
>
> Signed-off-by: Felipe Pena <felipensp@gmail.com>
> ---
>  tools/perf/util/trace-event-info.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
> index f3c9e55..2a0c3c9 100644
> --- a/tools/perf/util/trace-event-info.c
> +++ b/tools/perf/util/trace-event-info.c
> @@ -518,13 +518,15 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
>  			 "/tmp/perf-XXXXXX");
>  		if (!mkstemp(tdata->temp_file)) {
>  			pr_debug("Can't make temp file");
> -			return NULL;
> +			err = -1;
> +			goto err_tdata;
>  		}
>
>  		temp_fd = open(tdata->temp_file, O_RDWR);
>  		if (temp_fd < 0) {
>  			pr_debug("Can't read '%s'", tdata->temp_file);
> -			return NULL;
> +			err = -1;
> +			goto err_tdata;

I'd rather initialize err to -1 at the beginning.  And the malloc of
tdata should also be handled like this.

Thanks,
Namhyung


>  		}
>
>  		/*
> @@ -562,6 +564,7 @@ out:
>  		output_fd = fd;
>  	}
>
> +err_tdata:
>  	if (err) {
>  		free(tdata);
>  		tdata = NULL;
> --
> 1.7.10.4

      reply	other threads:[~2013-10-14  5:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-11  1:21 Felipe Pena
2013-10-14  5:07 ` Namhyung Kim [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=87fvs4bfuq.fsf@sejong.aot.lge.com \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=bp@suse.de \
    --cc=felipensp@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulus@samba.org \
    /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

Powered by JetHome