Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usbip: usbip_detach: Fix memory, udev context and udev leak

detach_port() fails to call usbip_vhci_driver_close() from its error
path after usbip_vhci_detach_device() returns failure, leaking memory
allocated in usbip_vhci_driver_open() and holding udev_context and udev
references. Fix it to call usbip_vhci_driver_close().

Signed-off-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Shuah Khan (Samsung OSG) and committed by
Greg Kroah-Hartman
d179f99a edf38004

+6 -3
+6 -3
tools/usb/usbip/src/usbip_detach.c
··· 43 43 44 44 static int detach_port(char *port) 45 45 { 46 - int ret; 46 + int ret = 0; 47 47 uint8_t portnum; 48 48 char path[PATH_MAX+1]; 49 49 ··· 73 73 } 74 74 75 75 ret = usbip_vhci_detach_device(portnum); 76 - if (ret < 0) 77 - return -1; 76 + if (ret < 0) { 77 + ret = -1; 78 + goto call_driver_close; 79 + } 78 80 81 + call_driver_close: 79 82 usbip_vhci_driver_close(); 80 83 81 84 return ret;