From: Johan Hovold <johan@kernel.org>
To: Gargi Sharma <gs051095@gmail.com>
Cc: outreachy-kernel@googlegroups.com, gregkh@linuxfoundation.org,
johan@kernel.org, elder@kernel.org
Subject: Re: [PATCH v2] staging: greybus: loopback_test: fix device-name leak
Date: Tue, 21 Feb 2017 20:50:59 +0100 [thread overview]
Message-ID: <20170221195059.GF10245@localhost> (raw)
In-Reply-To: <1487703983-19655-1-git-send-email-gs051095@gmail.com>
On Wed, Feb 22, 2017 at 12:36:23AM +0530, Gargi Sharma wrote:
> Change array index from the loop bound variable to loop index.
> Memory leak was occuring whenever there was more than one
> loopback device. The pointer to dirent structures must be
> individually freed before freeing the pointer array.
>
> Coccinelle Script:
> @@
> expression arr,ex1,ex2;
> @@
>
> for(ex1 = 0; ex1 < ex2; ex1++) { <...
> arr[
> - ex2
> + ex1
> ]
> ...> }
>
> Signed-off-by: Gargi Sharma <gs051095@gmail.com>
> ---
> Changes in v2:
> -Made the commit message clearer.
> ---
> drivers/staging/greybus/tools/loopback_test.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/greybus/tools/loopback_test.c b/drivers/staging/greybus/tools/loopback_test.c
> index 18d7a3d..1c01833 100644
> --- a/drivers/staging/greybus/tools/loopback_test.c
> +++ b/drivers/staging/greybus/tools/loopback_test.c
> @@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
> ret = 0;
> done:
> for (i = 0; i < n; i++)
> - free(namelist[n]);
> + free(namelist[i]);
> free(namelist);
> baddir:
> return ret;
Oh, there's an illegal free here, which probably was what Julia was
referring to. Yeah, not sure why things haven't blown up, perhaps there
happens to be NULL pointer after?
So we are in fact always leaking the device name here.
No need to resend, unless you prefer. You can add my Reviewed-by tag if
so.
Thanks,
Johan
next prev parent reply other threads:[~2017-02-21 19:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-21 19:06 [PATCH v2] staging: greybus: loopback_test: fix device-name leak Gargi Sharma
2017-02-21 19:45 ` Johan Hovold
2017-02-21 19:50 ` Johan Hovold [this message]
2017-02-22 10:15 ` [Outreachy kernel] " Gargi Sharma
2017-02-22 10:24 ` Julia Lawall
2017-02-22 10:37 ` Johan Hovold
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=20170221195059.GF10245@localhost \
--to=johan@kernel.org \
--cc=elder@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=gs051095@gmail.com \
--cc=outreachy-kernel@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 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.