Skip to contentSkip to conversation

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

PATCH New Shuah Khan (Samsung OSG) 1 participant 1 message May 29, 2018

Subsystems (2)
lore
Share & tools
lore

Shuah Khan (Samsung OSG)

author maintainer
#0 lore raw

PATCH 1/1 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().

---
 tools/usb/usbip/src/usbip_detach.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
tools/usb/usbip/src/usbip_detach.c +6 -3
index 9db9d21bb2ec..6a8db858caa5 100644
@@ -43,7 +43,7 @@ void usbip_detach_usage(void)
 
 static int detach_port(char *port)
 {
-	int ret;
+	int ret = 0;
 	uint8_t portnum;
 	char path[PATH_MAX+1];
 
@@ -73,9 +73,12 @@ static int detach_port(char *port)
 	}
 
 	ret = usbip_vhci_detach_device(portnum);
-	if (ret < 0)
-		return -1;
+	if (ret < 0) {
+		ret = -1;
+		goto call_driver_close;
+	}
 
+call_driver_close:
 	usbip_vhci_driver_close();
 
 	return ret;