All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Gargi Sharma <gs051095@gmail.com>
Cc: Johan Hovold <johan@kernel.org>,
	outreachy-kernel@googlegroups.com,
	Greg KH <gregkh@linuxfoundation.org>,
	elder@kernel.org
Subject: Re: [Outreachy kernel] Re: [PATCH v2] staging: greybus: loopback_test: fix device-name leak
Date: Wed, 22 Feb 2017 11:37:44 +0100	[thread overview]
Message-ID: <20170222103744.GI10245@localhost> (raw)
In-Reply-To: <CAOCi2DHkHpakjYezcnCXF35ViB5+LW174r_=AYMCt22OYg3X5g@mail.gmail.com>

On Wed, Feb 22, 2017 at 03:45:43PM +0530, Gargi Sharma wrote:
> On Wed, Feb 22, 2017 at 1:20 AM, Johan Hovold <johan@kernel.org> wrote:
> >
> > 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.
> 
> Um, should I assign null pointers to device names before freeing them? That
> should fix illegal free I believe.

No, your fix is fine as is, it's just a matter of describing the problem
accurately in the commit message.

> > No need to resend, unless you prefer. You can add my Reviewed-by tag if
> > so.
> Not sure what this means. I can send a v3 with the above suggested changes
> if they are correct.

Sorry if I was being unclear. I meant to say that your current commit
message is good enough, but perhaps it is indeed better if you do send a
v3 where you mention that we have been leaking all the device names
always (and not just when there have been more than one as I incorrectly
suggested).

You can also mention that you fix that illegal free of namelist[n],
which must so far have happened to be NULL (I verified that it is indeed
NULL here on my system too).

Thanks,
Johan


      parent reply	other threads:[~2017-02-22 10:37 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
2017-02-22 10:15   ` [Outreachy kernel] " Gargi Sharma
2017-02-22 10:24     ` Julia Lawall
2017-02-22 10:37     ` Johan Hovold [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=20170222103744.GI10245@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.