usb: gadget: f_dfu.c: fix memory leak

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>
This commit is contained in:
Ralph Siemsen 2019-06-28 10:42:02 -04:00 committed by Marek Vasut
parent ed3a37a248
commit fe876984a4

View 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;