UPSTREAM: 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().

Change-Id: I990f3874d6e3dca78036d6f30a05e765fbe38c67
Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
(cherry picked from commit fe876984a428cc0058bdb536ac948397762f3c0d)
This commit is contained in:
Ralph Siemsen 2019-06-28 10:42:02 -04:00 committed by Frank Wang
parent 384b75a5e8
commit 2b5fff1c93
1 changed files with 1 additions and 0 deletions

View File

@ -749,6 +749,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;