linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Yunfeng Ye <yeyunfeng@huawei.com>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@redhat.com,
	namhyung@kernel.org, linux-kernel@vger.kernel.org,
	hushiyuan@huawei.com, linfeilong@huawei.com
Subject: Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags()
Date: Wed, 16 Oct 2019 11:08:56 -0300	[thread overview]
Message-ID: <20191016140856.GG22835@kernel.org> (raw)
In-Reply-To: <f1dc9f3f-ce4a-9a62-1940-8ea8b7fea750@huawei.com>

Em Wed, Oct 16, 2019 at 09:19:54PM +0800, Yunfeng Ye escreveu:
> 
> 
> On 2019/10/16 21:09, Arnaldo Carvalho de Melo wrote:
> > Em Wed, Oct 16, 2019 at 10:04:03AM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu:
> >>> The memory @orig_flags is allocated by strdup(), it is freed on the
> >>> normal path, but leak to free on the error path.
> >>
> >> Are you using some tool to find out these problems? Or is it just visual
> >> inspection?
> > 
> By a static code anaylsis tool which not an open source tool. thanks.

Ok, so please state that next time, just for the fullest possible
disclosure and for people to realize to what extent problems in the
kernel and in tooling hosted in the kernel is being fixed by such tools.

I.e. you don't need to release the tool, not even give out its name,
just something like:

"Found by internal static analysis tool."

Thanks,

- Arnaldo
 
> > Anyway, applied after adding this to the commit log message:
> > 
> > Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string")
> > 
> ok, thanks.
> 
> > - Arnaldo
> >  
> >> - Arnaldo
> >>  
> >>> Fix this by adding free(orig_flags) on the error path.
> >>>
> >>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> >>> ---
> >>>  tools/perf/builtin-kmem.c | 1 +
> >>>  1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
> >>> index 1e61e353f579..9661671cc26e 100644
> >>> --- a/tools/perf/builtin-kmem.c
> >>> +++ b/tools/perf/builtin-kmem.c
> >>> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags)
> >>>  			new = realloc(new_flags, len + strlen(cpt) + 2);
> >>>  			if (new == NULL) {
> >>>  				free(new_flags);
> >>> +				free(orig_flags);
> >>>  				return NULL;
> >>>  			}
> >>>
> >>> -- 
> >>> 2.7.4.3
> >>
> >> -- 
> >>
> >> - Arnaldo
> > 

-- 

- Arnaldo

  reply	other threads:[~2019-10-16 14:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-16  8:38 [PATCH] perf kmem: Fix memory leak in compact_gfp_flags() Yunfeng Ye
2019-10-16 13:04 ` Arnaldo Carvalho de Melo
2019-10-16 13:09   ` Arnaldo Carvalho de Melo
2019-10-16 13:19     ` Yunfeng Ye
2019-10-16 14:08       ` Arnaldo Carvalho de Melo [this message]
2019-10-16 14:17         ` Yunfeng Ye
2019-10-21  6:26 ` [tip: perf/urgent] " tip-bot2 for 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=20191016140856.GG22835@kernel.org \
    --to=arnaldo.melo@gmail.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=hushiyuan@huawei.com \
    --cc=jolsa@redhat.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 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).