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>
This commit is contained in:
Heinrich Schuchardt 2014-02-27 14:25:19 +01:00 committed by Greg Kroah-Hartman
parent 6e2055a9e5
commit 696c9c7ffa

View File

@ -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) static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
{ {
struct usbip_exported_device *edev = NULL; struct usbip_exported_device *edev = NULL;
struct usbip_exported_device *edev_old;
size_t size; size_t size;
int i; int i;
@ -126,8 +127,10 @@ static struct usbip_exported_device *usbip_exported_device_new(char *sdevpath)
size = sizeof(*edev) + edev->udev.bNumInterfaces * size = sizeof(*edev) + edev->udev.bNumInterfaces *
sizeof(struct usbip_usb_interface); sizeof(struct usbip_usb_interface);
edev_old = edev;
edev = realloc(edev, size); edev = realloc(edev, size);
if (!edev) { if (!edev) {
edev = edev_old;
dbg("realloc failed"); dbg("realloc failed");
goto err; goto err;
} }