From: Heinrich Schuchardt <xypron.glpk@gmx.de>
Date: Thu, 27 Feb 2014 13:25:19 +0000 (+0100)
Subject: staging: usbip: userspace: Memory leak in usbip_exported_device_new
X-Git-Tag: firefly_0821_release~176^2~4193^2~798
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=696c9c7ffaeaeee5c9711f35503ab46ff3e1255e;p=firefly-linux-kernel-4.4.55.git

staging: usbip: userspace: Memory leak in usbip_exported_device_new

Memory was leaked and a device not closed if we ran out of memory on the
system.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---

diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
index 86a867582de6..35b2f5b0e350 100644
--- a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
+++ b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c
@@ -101,6 +101,7 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
 static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
 {
 	struct usbip_exported_device *edev = NULL;
+	struct usbip_exported_device *edev_old;
 	size_t size;
 	int i;
 
@@ -126,8 +127,10 @@ static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
 	size = sizeof(*edev) + edev->udev.bNumInterfaces *
 		sizeof(struct usbip_usb_interface);
 
+	edev_old = edev;
 	edev = realloc(edev, size);
 	if (!edev) {
+		edev = edev_old;
 		dbg("realloc failed");
 		goto err;
 	}