@@ -267,20 +267,28 @@ hackrf_device_list_t* ADDCALL hackrf_device_list()
267267{
268268 libusb_device_handle * usb_device = NULL ;
269269 hackrf_device_list_t * list = calloc (1 , sizeof (* list ));
270+ if ( list == NULL )
271+ return NULL ;
272+
270273 list -> usb_devicecount = libusb_get_device_list (g_libusb_context , (libusb_device * * * )& list -> usb_devices );
271274
272275 list -> serial_numbers = calloc (list -> usb_devicecount , sizeof (void * ));
273- list -> product_ids = calloc (list -> usb_devicecount , sizeof (int ));
276+ list -> usb_board_ids = calloc (list -> usb_devicecount , sizeof (enum hackrf_usb_board_id ));
274277 list -> usb_device_index = calloc (list -> usb_devicecount , sizeof (int ));
275278
279+ if ( list -> serial_numbers == NULL || list -> usb_board_ids == NULL || list -> usb_device_index == NULL ) {
280+ hackrf_device_list_free (list );
281+ return NULL ;
282+ }
283+
276284 for (ssize_t i = 0 ; i < list -> usb_devicecount ; i ++ ) {
277285 struct libusb_device_descriptor device_descriptor ;
278286 libusb_get_device_descriptor (list -> usb_devices [i ], & device_descriptor );
279287
280288 if ( device_descriptor .idVendor == hackrf_usb_vid ) {
281289 if ( (device_descriptor .idProduct == hackrf_one_usb_pid ) || (device_descriptor .idProduct == hackrf_jawbreaker_usb_pid ) ) {
282290 int idx = list -> devicecount ++ ;
283- list -> product_ids [idx ] = device_descriptor .idProduct ;
291+ list -> usb_board_ids [idx ] = device_descriptor .idProduct ;
284292 list -> usb_device_index [idx ] = i ;
285293
286294 const uint_fast8_t serial_descriptor_index = device_descriptor .iSerialNumber ;
@@ -318,7 +326,7 @@ void ADDCALL hackrf_device_list_free(hackrf_device_list_t *list)
318326 }
319327
320328 free (list -> serial_numbers );
321- free (list -> product_ids );
329+ free (list -> usb_board_ids );
322330 free (list -> usb_device_index );
323331 free (list );
324332}
0 commit comments