mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@redhat.com>
To: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: "Ingo Molnar" <mingo@elte.hu>,
	linux-kernel@vger.kernel.org,
	"Arnaldo Carvalho de Melo" <acme@redhat.com>,
	"Frédéric Weisbecker" <fweisbec@gmail.com>,
	"Mike Galbraith" <efault@gmx.de>,
	"Paul Mackerras" <paulus@samba.org>,
	"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	"Tom Zanussi" <tzanussi@gmail.com>
Subject: Re: [PATCH 3/5] perf probe: Fix some error exit paths
Date: Tue, 18 May 2010 21:07:43 -0400	[thread overview]
Message-ID: <4BF339DF.9070406@redhat.com> (raw)
In-Reply-To: <1274228881-8035-4-git-send-email-acme@infradead.org>

Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> That could leave filedescriptors open and leak memory. Also stop using
> xmalloc, use malloc and handle results just like other error cases in
> the same routine that used it.

Oops, thanks for fixing.
BTW, I found some other bugs... See below.

> 
> Cc: Frédéric Weisbecker <fweisbec@gmail.com>
> Cc: Masami Hiramatsu <mhiramat@redhat.com>
> Cc: Mike Galbraith <efault@gmx.de>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Tom Zanussi <tzanussi@gmail.com>
> LKML-Reference: <new-submission>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
>  tools/perf/util/probe-finder.c |   27 +++++++++++++++++----------
>  1 files changed, 17 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
> index 93583eb..0bfd46a 100644
> --- a/tools/perf/util/probe-finder.c
> +++ b/tools/perf/util/probe-finder.c
> @@ -743,32 +743,34 @@ static int find_lazy_match_lines(struct list_head *head,
>  				 const char *fname, const char *pat)
>  {
>  	char *fbuf, *p1, *p2;
> -	int fd, ret, line, nlines = 0;
> +	int fd, line, nlines = -1;
>  	struct stat st;
>  
>  	fd = open(fname, O_RDONLY);
>  	if (fd < 0) {

I think "fd = -errno;" should be here.

>  		pr_warning("Failed to open %s: %s\n", fname, strerror(-fd));
> -		return fd;
> +		return -1;

Here is also better to return fd (= -errno).

>  	}
>  
> -	ret = fstat(fd, &st);
> -	if (ret < 0) {
> +	nlines = fstat(fd, &st);
> +	if (nlines < 0) {
>  		pr_warning("Failed to get the size of %s: %s\n",
>  			   fname, strerror(errno));
> -		return ret;
> +		goto out_close;
>  	}
> -	fbuf = xmalloc(st.st_size + 2);
> -	ret = read(fd, fbuf, st.st_size);
> -	if (ret < 0) {
> +	fbuf = malloc(st.st_size + 2);
> +	if (fbuf == NULL)

Here, we should set nlines = -ENOMEM;

> +		goto out_close;
> +	nlines = read(fd, fbuf, st.st_size);
> +	if (nlines < 0) {
>  		pr_warning("Failed to read %s: %s\n", fname, strerror(errno));
> -		return ret;
> +		goto out_free_fbuf;
>  	}
> -	close(fd);
>  	fbuf[st.st_size] = '\n';	/* Dummy line */
>  	fbuf[st.st_size + 1] = '\0';
>  	p1 = fbuf;
>  	line = 1;
> +	nlines = 0;
>  	while ((p2 = strchr(p1, '\n')) != NULL) {
>  		*p2 = '\0';
>  		if (strlazymatch(p1, pat)) {
> @@ -778,7 +780,10 @@ static int find_lazy_match_lines(struct list_head *head,
>  		line++;
>  		p1 = p2 + 1;
>  	}
> +out_free_fbuf:
>  	free(fbuf);
> +out_close:
> +	close(fd);
>  	return nlines;
>  }
>  
> @@ -955,6 +960,8 @@ int find_kprobe_trace_events(int fd, struct perf_probe_event *pev,
>  	if (!dbg) {
>  		pr_warning("No dwarf info found in the vmlinux - "
>  			"please rebuild with CONFIG_DEBUG_INFO=y.\n");
> +		free(pf.tevs);
> +		*tevs = NULL;
>  		return -EBADF;
>  	}
>  

Thank you,

-- 
Masami Hiramatsu
e-mail: mhiramat@redhat.com

  reply	other threads:[~2010-05-19  1:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-19  0:27 [GIT PULL 0/5] perf tools fixes and improvements Arnaldo Carvalho de Melo
2010-05-19  0:27 ` [PATCH 1/5] perf stat: add perf stat -B to pretty print large numbers Arnaldo Carvalho de Melo
2010-05-19  0:27 ` [PATCH 2/5] perf tools: Remove some unused functions Arnaldo Carvalho de Melo
2010-05-19  0:27 ` [PATCH 3/5] perf probe: Fix some error exit paths Arnaldo Carvalho de Melo
2010-05-19  1:07   ` Masami Hiramatsu [this message]
2010-05-19  0:28 ` [PATCH 4/5] perf probe: Don't call die() Arnaldo Carvalho de Melo
2010-05-19  0:33   ` Masami Hiramatsu
2010-05-19  0:28 ` [PATCH 5/5] perf tools: remove xstrndup, xmalloc, xzalloc 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=4BF339DF.9070406@redhat.com \
    --to=mhiramat@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@infradead.org \
    --cc=acme@redhat.com \
    --cc=efault@gmx.de \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=tzanussi@gmail.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

Powered by JetHome