Free the device list in ftdi_usb_find_all
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Tue, 21 Jun 2011 13:04:05 +0000 (15:04 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 21 Jun 2011 13:06:23 +0000 (15:06 +0200)
This fixes the leak with examples/find_all

src/ftdi.c

index 0893421..33b6a50 100644 (file)
@@ -289,13 +289,13 @@ int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devli
         struct libusb_device_descriptor desc;
 
         if (libusb_get_device_descriptor(dev, &desc) < 0)
-            ftdi_error_return(-6, "libusb_get_device_descriptor() failed");
+            ftdi_error_return_free_device_list(-6, "libusb_get_device_descriptor() failed", devs);
 
         if (desc.idVendor == vendor && desc.idProduct == product)
         {
             *curdev = (struct ftdi_device_list*)malloc(sizeof(struct ftdi_device_list));
             if (!*curdev)
-                ftdi_error_return(-3, "out of memory");
+                ftdi_error_return_free_device_list(-3, "out of memory", devs);
 
             (*curdev)->next = NULL;
             (*curdev)->dev = dev;
@@ -304,7 +304,7 @@ int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devli
             count++;
         }
     }
-
+    libusb_free_device_list(devs,1);
     return count;
 }