From 4ca71d29e44d3c5baaab35ffeabab1fb18bae9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 15 Jun 2012 10:58:47 +0200 Subject: fix libusb_get_device_list segv --- libk8055/libk8055.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c index 80b7e5f..40bf6bd 100644 --- a/libk8055/libk8055.c +++ b/libk8055/libk8055.c @@ -246,7 +246,7 @@ int k8055_open_device( struct k8055_dev* dev, int board_address ) { libusb_device** list; libusb_device* found = NULL; libusb_init( &dev->usb_ctx ); - ssize_t cnt = libusb_get_device_list( NULL, &list ); + ssize_t cnt = libusb_get_device_list( dev->usb_ctx, &list ); if( cnt<0 ) { if( dev->debug_level>0 ) fprintf( stderr, "Unable to list usb devices\n" ); return K8055_ERROR; @@ -266,14 +266,17 @@ int k8055_open_device( struct k8055_dev* dev, int board_address ) { } } if( found==NULL ) { + libusb_free_device_list(list,1); if( dev->debug_level>0 ) fprintf( stderr, "No Velleman device found.\n" ); return K8055_ERROR; } dev->usb_handle = NULL; if( libusb_open( found , &dev->usb_handle )!=0 ) { + libusb_free_device_list(list,1); if( dev->debug_level>0 ) fprintf( stderr,"usb_open failure\n" ); return K8055_ERROR; } + libusb_free_device_list(list,1); if( k8055_takeover_device( dev, 0 )!=0 ) { if( dev->debug_level>0 ) fprintf( stderr, "Can not take over the device from the OS driver\n" ); libusb_release_interface( dev->usb_handle, 0 ); @@ -326,7 +329,7 @@ int k8055_search_devices( int verbose ) { libusb_device** list; struct libusb_device_descriptor usb_descr; libusb_init( &usb_ctx ); - ssize_t cnt = libusb_get_device_list( NULL, &list ); + ssize_t cnt = libusb_get_device_list( usb_ctx, &list ); for ( ssize_t i=0; i0 ) fprintf( stderr,"found devices : %X\n", ret ); + libusb_free_device_list(list,1); libusb_exit( usb_ctx ); return ret; } -- cgit v1.1-2-g2b99