From: Serge Semin <fancer.lancer@gmail.com>
To: Colin King <colin.king@canonical.com>
Cc: Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
Allen Hubbe <allenbh@gmail.com>,
linux-ntb@googlegroups.com, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] NTB: ntb_tool: fix memory leak on 'buf' on error exit path
Date: Mon, 22 Jan 2018 13:02:39 +0300 [thread overview]
Message-ID: <20180122100239.GA32024@mobilestation> (raw)
In-Reply-To: <20180122093857.2174-1-colin.king@canonical.com>
On Mon, Jan 22, 2018 at 09:38:57AM +0000, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently there is a memory leak on buf when the call to ntb_mw_get_align
> fails. Add an exit err label and jump to this so that kfree on buf frees
> the memory.
>
> Detected by CoverityScan, CID#1464286 ("Resource leak")
>
> Fixes: d637628ce00c ("NTB: ntb_tool: Add full multi-port NTB API support")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Good catch, thanks!
Acked-by: Serge Semin <fancer.lancer@gmail.com>
> ---
> drivers/ntb/test/ntb_tool.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c
> index 920fc9b161b0..d592c0ffbd19 100644
> --- a/drivers/ntb/test/ntb_tool.c
> +++ b/drivers/ntb/test/ntb_tool.c
> @@ -659,7 +659,7 @@ static ssize_t tool_mw_trans_read(struct file *filep, char __user *ubuf,
> ret = ntb_mw_get_align(inmw->tc->ntb, inmw->pidx, inmw->widx,
> &addr_align, &size_align, &size_max);
> if (ret)
> - return ret;
> + goto err;
>
> off += scnprintf(buf + off, buf_size - off,
> "Inbound MW \t%d\n",
> @@ -694,6 +694,8 @@ static ssize_t tool_mw_trans_read(struct file *filep, char __user *ubuf,
> &size_max);
>
> ret = simple_read_from_buffer(ubuf, size, offp, buf, off);
> +
> +err:
> kfree(buf);
>
> return ret;
> --
> 2.15.1
>
next prev parent reply other threads:[~2018-01-22 10:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-22 9:38 [PATCH][next] NTB: ntb_tool: fix memory leak on 'buf' on error exit path Colin King
2018-01-22 10:02 ` Serge Semin [this message]
2018-01-24 4:06 ` Jon Mason
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=20180122100239.GA32024@mobilestation \
--to=fancer.lancer@gmail.com \
--cc=allenbh@gmail.com \
--cc=colin.king@canonical.com \
--cc=dave.jiang@intel.com \
--cc=jdmason@kudzu.us \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-ntb@googlegroups.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).