[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cdi-devel] [PATCH] Memleak in USB 1.1



From: Max Reitz <max@xxxxxxxxxx>

! Fixed the memleak mentioned by Matthew

Signed-off-by: Max Reitz <max@xxxxxxxxxx>
---
 usb11/control.c |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/usb11/control.c b/usb11/control.c
index 4151aa5..d7723c8 100644
--- a/usb11/control.c
+++ b/usb11/control.c
@@ -34,7 +34,7 @@ static int usb_dev_ids = 1;
 
 static void enumerate_hub(struct cdi_usb_device *usbdev);
 
-void usb11_enumerate(struct cdi_usb_device *device)
+static int usb11_real_enumerate(struct cdi_usb_device *device)
 {
     struct endpoint_desc *ep0;
     struct device_desc *dev_desc;
@@ -71,7 +71,7 @@ void usb11_enumerate(struct cdi_usb_device *device)
     dev_desc = usb11_do_control(device, DEV_TO_HOST, NULL, 8, STD_REQUEST,
         REC_DEVICE, GET_DESCRIPTOR, DESC_DEVICE << 8, 0);
     if (dev_desc == NULL) {
-        return;
+        return 0;
     }
     ep0->max_packet_size = dev_desc->max_packet_size0;
 
@@ -102,7 +102,7 @@ void usb11_enumerate(struct cdi_usb_device *device)
             REC_DEVICE, GET_DESCRIPTOR,
             (DESC_STRING << 8) | dev_desc->iManufacturer, 0);
         if (name == NULL) {
-            return;
+            return 0;
         }
         d1printf(" -> Manufacturer: ");
         for (int i = 2; i < name[0]; i += 2) {
@@ -115,7 +115,7 @@ void usb11_enumerate(struct cdi_usb_device *device)
             REC_DEVICE, GET_DESCRIPTOR,
             (DESC_STRING << 8) | dev_desc->iProduct, 0);
         if (name == NULL) {
-            return;
+            return 0;
         }
         d1printf(" -> Product: ");
         for (int i = 2; i < name[0]; i += 2) {
@@ -128,13 +128,13 @@ void usb11_enumerate(struct cdi_usb_device *device)
         sizeof(struct config_desc), STD_REQUEST, REC_DEVICE, GET_DESCRIPTOR,
         DESC_CONFIGURATION << 8, 0);
     if (conf_desc == NULL) {
-        return;
+        return 0;
     }
     conf_desc = usb11_do_control(device, DEV_TO_HOST, NULL,
         conf_desc->total_length, STD_REQUEST, REC_DEVICE, GET_DESCRIPTOR,
         DESC_CONFIGURATION << 8, 0);
     if (conf_desc == NULL) {
-        return;
+        return 0;
     }
     device->config_desc = conf_desc;
     usb11_do_control(device, HOST_TO_DEV, NULL, 0, STD_REQUEST, REC_DEVICE,
@@ -144,7 +144,7 @@ void usb11_enumerate(struct cdi_usb_device *device)
             REC_DEVICE, GET_DESCRIPTOR,
             (DESC_STRING << 8) | conf_desc->iConfiguration, 0);
         if (name == NULL) {
-            return;
+            return 0;
         }
         d1printf("Using configuration ");
         for (int i = 2; i < name[0]; i += 2) {
@@ -174,7 +174,7 @@ void usb11_enumerate(struct cdi_usb_device *device)
             REC_DEVICE, GET_DESCRIPTOR,
             (DESC_STRING << 8) | best_if->iInterface, 0);
         if (name == NULL) {
-            return;
+            return 0;
         }
         d1printf("Using interface ");
         for (int i = 2; i < name[0]; i += 2) {
@@ -198,6 +198,16 @@ void usb11_enumerate(struct cdi_usb_device *device)
     if (best_if->interface_class == USBDC_HUB) {
         enumerate_hub(device);
     }
+
+    return 1;
+}
+
+void usb11_enumerate(struct cdi_usb_device *device)
+{
+    if (!usb11_real_enumerate(device)) {
+        free(device->ep0->endpoint);
+        free(device->ep0);
+    }
 }
 
 static void reset_hub_device(struct cdi_usb_device *usbdev)
-- 
1.6.4.2