Staging: serqt_usb2: fix memory leak in error case
authorOliver Neukum <oliver@neukum.org>
Mon, 13 Jul 2009 08:46:57 +0000 (10:46 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 28 Jul 2009 21:07:10 +0000 (14:07 -0700)
a standard memory leak, as later allocations may fail even if prior
allocations did not. Then the prior allocations must be undone.

Signed-off-by: Oliver Neukum <oliver@neukum.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/serqt_usb2/serqt_usb2.c

index f9ff9c266780a9a0c3f2d19373bd96c1e8b7a78c..0fdf8c6dc648a69eaeeac311b1e24a3cb51d85e9 100644 (file)
@@ -738,6 +738,11 @@ static int qt_startup(struct usb_serial *serial)
                if (!qt_port) {
                        dbg("%s: kmalloc for quatech_port (%d) failed!.",
                            __func__, i);
+                       for(--i; i >= 0; i--) {
+                               port = serial->port[i];
+                               kfree(usb_get_serial_port_data(port));
+                               usb_set_serial_port_data(port, NULL);
+                       }
                        return -ENOMEM;
                }
                spin_lock_init(&qt_port->lock);