Hi, > -----Original Message----- > From: linux-usb-owner@xxxxxxxxxxxxxxx [mailto:linux-usb- > owner@xxxxxxxxxxxxxxx] On Behalf Of Sergei Shtylyov > Sent: Tuesday, June 10, 2014 6:25 PM > To: Krzysztof Opasiak; mporter@xxxxxxxxxx > Cc: linux-usb@xxxxxxxxxxxxxxx; philippedeswert@xxxxxxxxx; 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 <k.opasiak@xxxxxxxxxxx> > > --- > > 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 k.opasiak@xxxxxxxxxxx -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html