From f7a5d7b3ab3c4865af85b431e1cd18b66b6c3b0e Mon Sep 17 00:00:00 2001 From: Elad Wexler Date: Sat, 30 Dec 2017 18:01:39 +0200 Subject: tools: usb: usbip: fix fd leak in case of 'fread' failure Fix possible resource leak: fd Signed-off-by: Elad Wexler Acked-by: Shuah Khan Signed-off-by: Greg Kroah-Hartman --- tools/usb/usbip/libsrc/usbip_device_driver.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c index b2dac82975af..ec3a0b794f15 100644 --- a/tools/usb/usbip/libsrc/usbip_device_driver.c +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c @@ -92,7 +92,7 @@ int read_usb_vudc_device(struct udev_device *sdev, struct usbip_usb_device *dev) return -1; ret = fread((char *) &descr, sizeof(descr), 1, fd); if (ret < 0) - return -1; + goto err; fclose(fd); copy_descr_attr(dev, &descr, bDeviceClass); @@ -124,6 +124,9 @@ int read_usb_vudc_device(struct udev_device *sdev, struct usbip_usb_device *dev) name = udev_device_get_sysname(plat); strncpy(dev->busid, name, SYSFS_BUS_ID_SIZE); return 0; +err: + fclose(fd); + return -1; } static int is_my_device(struct udev_device *dev) -- cgit v1.2.3