linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Leo Yan <leo.yan@linaro.org>
Cc: gushengxian <gushengxian507419@gmail.com>,
	will@kernel.org, mathieu.poirier@linaro.org,
	peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@redhat.com,
	namhyung@kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	gushengxian <gushengxian@yulong.com>
Subject: Re: [PATCH] perf: tests: fix some mmemory leak issues
Date: Fri, 2 Jul 2021 14:57:51 -0300	[thread overview]
Message-ID: <YN9TnyUMd0VesywP@kernel.org> (raw)
In-Reply-To: <20210702135641.GA22592@leoy-ThinkPad-X240s>

Em Fri, Jul 02, 2021 at 09:56:41PM +0800, Leo Yan escreveu:
> Hi Arnaldo,
> 
> On Fri, Jul 02, 2021 at 09:58:52AM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Jul 01, 2021 at 09:09:55PM -0700, gushengxian escreveu:
> > > From: gushengxian <gushengxian@yulong.com>
> > > 
> > > Some memory leak issues should be fixed by free().
> > > Reported by cppcheck.
> 
> I don't think this patch does the right thing.  You could see that the
> memory is allocated in arch specific function sample_ustack(), and the
> "buf" pointer is assigned to sample->user_stack.data; and the memory
> actually is released in the caller function test_dwarf_unwind__thread:
> 
> noinline int test_dwarf_unwind__thread(struct thread *thread)
> {
>         struct perf_sample sample;
>         unsigned long cnt = 0;
>         int err = -1;
> 
>         memset(&sample, 0, sizeof(sample));
> 
>         if (test__arch_unwind_sample(&sample, thread)) {
>                 pr_debug("failed to get unwind sample\n");
>                 goto out;
>         } 
> 
>         [...]
> 
>  out:
>         zfree(&sample.user_stack.data);
>         zfree(&sample.user_regs.regs);
>         return err;
> }
> 
> So this patch will break the testing and doesn't fix any memory leak
> issue.

You are right, those buffers are allocated in those functions and then
_returned_ via sample->user_stack, the tool (and myself, ugh) got
fooled, I'll remove that from my local tree.

Thanks Leo!

- Arnaldo

      reply	other threads:[~2021-07-02 17:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-02  4:09 [PATCH] perf: tests: fix some mmemory leak issues gushengxian
2021-07-02 12:58 ` Arnaldo Carvalho de Melo
2021-07-02 13:56   ` Leo Yan
2021-07-02 17:57     ` Arnaldo Carvalho de Melo [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=YN9TnyUMd0VesywP@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=gushengxian507419@gmail.com \
    --cc=gushengxian@yulong.com \
    --cc=jolsa@redhat.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will@kernel.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;
as well as URLs for NNTP newsgroup(s).