usb: gadget: don't leak configs when unbinding
authorStephen Warren <swarren@nvidia.com>
Sat, 5 Sep 2015 04:03:42 +0000 (22:03 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 11 Sep 2015 21:15:21 +0000 (17:15 -0400)
By the time g_dnl_unbind() is run, cdev->config has been set to NULL,
so the free() there does nothing, and the config struct is leaked.
Equally, struct usb_gadget contains a linked list of config structs, so
the code should iterate over them all and free each one, rather than
freeing one particular config struct.

composite_unbind() already iterates over the list of config structs, and
unlinks each from the linked list. Fix this loop to free() each struct as
it's unlinked and otherwise forgotten.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
drivers/usb/gadget/composite.c
drivers/usb/gadget/g_dnl.c

index d96296c..a13b21d 100644 (file)
@@ -948,6 +948,7 @@ static void composite_unbind(struct usb_gadget *gadget)
                        debug("unbind config '%s'/%p\n", c->label, c);
                        c->unbind(c);
                }
+               free(c);
        }
        if (composite->unbind)
                composite->unbind(cdev);
index ad89a0d..2fa6da4 100644 (file)
@@ -93,8 +93,6 @@ static int g_dnl_unbind(struct usb_composite_dev *cdev)
 {
        struct usb_gadget *gadget = cdev->gadget;
 
-       free(cdev->config);
-       cdev->config = NULL;
        debug("%s: calling usb_gadget_disconnect for "
                        "controller '%s'\n", __func__, gadget->name);
        usb_gadget_disconnect(gadget);