From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752478AbeAXEGw (ORCPT ); Tue, 23 Jan 2018 23:06:52 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:37984 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752274AbeAXEGu (ORCPT ); Tue, 23 Jan 2018 23:06:50 -0500 X-Google-Smtp-Source: AH8x224fjI1oAHL+oTkDdpNVBk8TMU4vsgr00SAyHY2cdpsnIJE6LN9lBod2OeNBAV5tITvWTrZaXw== Date: Tue, 23 Jan 2018 23:06:47 -0500 From: Jon Mason To: Serge Semin Cc: Colin King , Dave Jiang , Allen Hubbe , 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 Message-ID: <20180124040646.GA20474@kudzu.us> References: <20180122093857.2174-1-colin.king@canonical.com> <20180122100239.GA32024@mobilestation> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180122100239.GA32024@mobilestation> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 22, 2018 at 01:02:39PM +0300, Serge Semin wrote: > On Mon, Jan 22, 2018 at 09:38:57AM +0000, Colin King wrote: > > From: Colin Ian King > > > > 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 > > Good catch, thanks! > > Acked-by: Serge Semin Applied to ntb-next Thanks, Jon > > > --- > > 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 > >