From: Seung-Woo Kim Date: Tue, 25 Jul 2017 06:30:02 +0000 (+0900) Subject: cmd: usbdown: remove memory leak on usbdown_get_alt() X-Git-Tag: submit/tizen/20191107.042334~124 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d52e3639d79315ad16b3cbeb76470487fc00632d;p=platform%2Fkernel%2Fu-boot.git cmd: usbdown: remove memory leak on usbdown_get_alt() The string name_bkp is duplicated but never deallocated and it causes memory leak. Remove the memory leak on usb_don_get_alt() with adding goto label 'out' which calls free. Change-Id: Iae5a111c3ca4e6e81526374daa06e8be1f6de252 Signed-off-by: Seung-Woo Kim --- diff --git a/cmd/usbdown.c b/cmd/usbdown.c index 840c6bb86c..4ff6aeca66 100644 --- a/cmd/usbdown.c +++ b/cmd/usbdown.c @@ -94,9 +94,10 @@ int usbdown_get_alt(const char *name) struct usbdown_entity *usb; const char *argv[3]; const char **parg = argv; - char *name_bkp; + char *name_bkp = NULL; const char *find_name; char *str; + int ret = -ENODEV; if (name[0] == '/') { name_bkp = strdup(name); @@ -104,7 +105,8 @@ int usbdown_get_alt(const char *name) *parg = strsep(&name_bkp, "/"); if (*parg == NULL) { printk("Invalid number of arguments.\n"); - return -ENODEV; + ret = -ENODEV; + goto out; } } @@ -115,19 +117,26 @@ int usbdown_get_alt(const char *name) list_for_each_entry(usb, &usbdown_list, list) { if (usb->name[0] != '/') { - if (!strncmp(usb->name, find_name, strlen(usb->name))) - return usb->alt_num; + if (!strncmp(usb->name, find_name, strlen(usb->name))) { + ret = usb->alt_num; + goto out; + } } else { str = strstr(usb->name, find_name); if (!str) continue; if (strlen(usb->name) == - ((str - usb->name) + strlen(find_name))) - return usb->alt_num; + ((str - usb->name) + strlen(find_name))) { + ret = usb->alt_num; + goto out; + } } } - return -ENODEV; +out: + if (name_bkp) + free(name_bkp); + return ret; } static int usb_fill_entity(struct usbdown_entity *usb, char *s, int alt_num,