Hi, > -----Original Message----- > From: [email protected] [mailto:linux-usb- > [email protected]] On Behalf Of Sergei Shtylyov > Sent: Tuesday, June 10, 2014 6:25 PM > To: Krzysztof Opasiak; [email protected] > Cc: [email protected]; [email protected]; Stanislaw > Wadas; Andrzej Pietrasiewicz; Karol Lewandowski; Marek Szyprowski; > Robert Baldyga > Subject: Re: [PATCH 1/3] libusbg: Fix potential memory leak in > usbg_init() > > Hello. > > On 06/10/2014 07:57 PM, Krzysztof Opasiak wrote: > > > Memory allocated with asprintf() for variable path > > could be not free() in some cases. Fix this issue by > > doing some small refactoring. > > > Signed-off-by: Krzysztof Opasiak <[email protected]> > > --- > > src/usbg.c | 34 +++++++++++++++++++++++----------- > > 1 file changed, 23 insertions(+), 11 deletions(-) > > > diff --git a/src/usbg.c b/src/usbg.c > > index edb7fc3..054c603 100644 > > --- a/src/usbg.c > > +++ b/src/usbg.c > [...] > > @@ -1227,21 +1228,32 @@ int usbg_init(char *configfs_path, > usbg_state **state) > [...] > > + ret = usbg_init_state(path, s); > > + if (ret != USBG_SUCCESS) { > > + ERRORNO("couldn't init gadget state\n"); > > + usbg_free_state(s); > > + goto out; > > + } > > + > > + *state = s; > > +out: > > + return ret; > > + > > +err: > > + free(path); > > Why not put the 'out' label here and not duplicate *return*?
That's because free(path) should not be executed in some cases. Function usbg_init_state() takes the ownership of memory allocated for path and it is free() along with usbg_state structure in usbg_free_state(). So after usbg_init_state() call we should use usbg_free_state and not free the path directly. -- BR's Krzysztof Opasiak Samsung R&D Institute Poland Samsung Electronics [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
