All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Yunfeng Ye <yeyunfeng@huawei.com>
Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	namhyung@kernel.org, linux-kernel@vger.kernel.org,
	"hushiyuan@huawei.com" <hushiyuan@huawei.com>,
	"linfeilong@huawei.com" <linfeilong@huawei.com>
Subject: Re: [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc()
Date: Fri, 25 Oct 2019 14:01:54 +0200	[thread overview]
Message-ID: <20191025120154.GA25352@krava> (raw)
In-Reply-To: <9d5f26f8-9429-bcb6-d491-cb789f761ea2@huawei.com>

On Fri, Oct 25, 2019 at 05:42:47PM +0800, Yunfeng Ye wrote:
> A memory leak in c2c_he_zalloc() is found by visual inspection.
> 
> Fix this by adding memory free on the error paths in c2c_he_zalloc().
> 
> Fixes: 7f834c2e84bb ("perf c2c report: Display node for cacheline address")
> Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key")
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  tools/perf/builtin-c2c.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
> index e69f44941aad..ad7d38a9dcbe 100644
> --- a/tools/perf/builtin-c2c.c
> +++ b/tools/perf/builtin-c2c.c
> @@ -138,21 +138,29 @@ static void *c2c_he_zalloc(size_t size)
> 
>  	c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
>  	if (!c2c_he->cpuset)
> -		return NULL;
> +		goto free_c2c_he;
> 
>  	c2c_he->nodeset = bitmap_alloc(c2c.nodes_cnt);
>  	if (!c2c_he->nodeset)
> -		return NULL;
> +		goto free_cpuset;
> 
>  	c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
>  	if (!c2c_he->node_stats)
> -		return NULL;
> +		goto free_nodeset;
> 
>  	init_stats(&c2c_he->cstats.lcl_hitm);
>  	init_stats(&c2c_he->cstats.rmt_hitm);
>  	init_stats(&c2c_he->cstats.load);
> 
>  	return &c2c_he->he;
> +
> +free_nodeset:
> +	free(c2c_he->nodeset);
> +free_cpuset:
> +	free(c2c_he->cpuset);
> +free_c2c_he:
> +	free(c2c_he);
> +	return NULL;
>  }
> 
>  static void c2c_he_free(void *he)
> -- 
> 2.7.4
> 


  reply	other threads:[~2019-10-25 12:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-25  9:42 [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc() Yunfeng Ye
2019-10-25 12:01 ` Jiri Olsa [this message]
2019-11-26  3:00   ` Yunfeng Ye

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=20191025120154.GA25352@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=hushiyuan@huawei.com \
    --cc=linfeilong@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=yeyunfeng@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.