OSDN Git Service

usbip: usbip_detach: Fix memory, udev context and udev leak
authorShuah Khan (Samsung OSG) <shuah@kernel.org>
Tue, 29 May 2018 22:13:03 +0000 (16:13 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 6 Aug 2018 14:24:31 +0000 (16:24 +0200)
[ Upstream commit d179f99a651685b19333360e6558110da2fe9bd7 ]

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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/usb/usbip/src/usbip_detach.c

index 9db9d21..6a8db85 100644 (file)
@@ -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;