libftdi Archives

Subject: 1.0/src/ftdi.c: Free the device list in ftdi_usb_find_all

From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 21 Jun 2011 15:04:05 +0200
This fixes the leak with examples/find_all
-- 
Uwe Bonnes                bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
>From e059f38fdd073004e73534d677f53e7b633850bb Mon Sep 17 00:00:00 2001
From: Uwe Bonnes <bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 21 Jun 2011 15:00:37 +0200
Subject: Free the device list in ftdi_usb_find_all

---
 src/ftdi.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/ftdi.c b/src/ftdi.c
index d5c4fbd..2cd452f 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -285,13 +285,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;
@@ -300,7 +300,7 @@ int ftdi_usb_find_all(struct ftdi_context *ftdi, struct 
ftdi_device_list **devli
             count++;
         }
     }
-
+    libusb_free_device_list(devs,1);
     return count;
 }
 
-- 
1.7.3.4


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • 1.0/src/ftdi.c: Free the device list in ftdi_usb_find_all, Uwe Bonnes <=