All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Andi Kleen <ak@linux.intel.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1] perf record: fix memory leak on AIO objects deallocation
Date: Thu, 6 Dec 2018 14:05:35 -0300	[thread overview]
Message-ID: <20181206170535.GK19069@kernel.org> (raw)
In-Reply-To: <e5d3154e-1583-83bb-9527-28ddbc6dbf9d@linux.intel.com>

Em Wed, Dec 05, 2018 at 08:19:41PM +0300, Alexey Budankov escreveu:
> 
> Sending a part which was missed between v12 and v13 of the patch set
> introducing AIO trace streaming for perf record mode. 
> 
> The part is essential to avoid memory leakage during deallocation
> of AIO related trace data buffers.
> 
> It is applied on top of acme perf/core repo.
> 
> Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
> ---
> tools/perf/util/mmap.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c
> index ab30555d2afc..169d02973757 100644
> --- a/tools/perf/util/mmap.c
> +++ b/tools/perf/util/mmap.c
> @@ -207,8 +207,18 @@ static int perf_mmap__aio_mmap(struct perf_mmap *map, struct mmap_params *mp)
>  
>  static void perf_mmap__aio_munmap(struct perf_mmap *map)
>  {
> +	int i;
> +
> +	for (i = 0; i < map->aio.nr_cblocks; ++i) {
> +		if (map->aio.data[i])
> +			zfree(&map->aio.data[i]);
> +	}
>  	if (map->aio.data)
>  		zfree(&map->aio.data);
> +	if (map->aio.cblocks)
> +		zfree(&map->aio.cblocks);
> +	if (map->aio.aiocb)
> +		zfree(&map->aio.aiocb);

There is no need to check for NULL before calling zfree(), as it is just
a wrapper for free that sets that variable to NULL after calling it.

And free(NULL) is valid, just a noop to avoid having all those tests
before each call to free(). I'm making those plain zfree() and later
will do a sweep at removing other cases.

>  }
>  
>  int perf_mmap__aio_push(struct perf_mmap *md, void *to, int idx,

-- 

- Arnaldo

  reply	other threads:[~2018-12-06 17:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-05 17:19 [PATCH v1] perf record: fix memory leak on AIO objects deallocation Alexey Budankov
2018-12-06 17:05 ` Arnaldo Carvalho de Melo [this message]
2018-12-06 18:10   ` Alexey Budankov
2018-12-14 20:58 ` [tip:perf/core] perf record: Fix " tip-bot for Alexey Budankov
2018-12-18 14:25 ` tip-bot for Alexey Budankov

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=20181206170535.GK19069@kernel.org \
    --to=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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 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.