usb: gadget: f_dfu.c: fix memory leak
authorRalph Siemsen <ralph.siemsen@linaro.org>
Fri, 28 Jun 2019 14:42:02 +0000 (10:42 -0400)
committerMarek Vasut <marex@denx.de>
Thu, 8 Aug 2019 09:35:02 +0000 (11:35 +0200)
dfu_prepare_function() allocates N+1 descriptor header structures,
the last one being the "DFU Functional Descriptor".

dfu_unbind() handles de-allocation, but fails to free the final
one (eg. "DFU Functional Descriptor"), leading to memory leak.

Fixed by incrementing counter, as in dfu_prepare_function().

Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>
drivers/usb/gadget/f_dfu.c

index 30ece52..e27f146 100644 (file)
@@ -748,6 +748,7 @@ static void dfu_unbind(struct usb_configuration *c, struct usb_function *f)
 
        if (f_dfu->function) {
                i = alt_num;
+               i++; /* free DFU Functional Descriptor */
                while (i) {
                        free(f_dfu->function[--i]);
                        f_dfu->function[i] = NULL;