lib: check for libusb init failure

master
Hoernchen 10 years ago
parent 5c376fc79c
commit e3c03f738f
  1. 22
      src/librtlsdr.c

@ -1298,14 +1298,16 @@ static rtlsdr_dongle_t *find_known_device(uint16_t vid, uint16_t pid)
uint32_t rtlsdr_get_device_count(void) uint32_t rtlsdr_get_device_count(void)
{ {
int i; int i,r;
libusb_context *ctx; libusb_context *ctx;
libusb_device **list; libusb_device **list;
uint32_t device_count = 0; uint32_t device_count = 0;
struct libusb_device_descriptor dd; struct libusb_device_descriptor dd;
ssize_t cnt; ssize_t cnt;
libusb_init(&ctx); r = libusb_init(&ctx);
if(r < 0)
return 0;
cnt = libusb_get_device_list(ctx, &list); cnt = libusb_get_device_list(ctx, &list);
@ -1325,7 +1327,7 @@ uint32_t rtlsdr_get_device_count(void)
const char *rtlsdr_get_device_name(uint32_t index) const char *rtlsdr_get_device_name(uint32_t index)
{ {
int i; int i,r;
libusb_context *ctx; libusb_context *ctx;
libusb_device **list; libusb_device **list;
struct libusb_device_descriptor dd; struct libusb_device_descriptor dd;
@ -1333,7 +1335,9 @@ const char *rtlsdr_get_device_name(uint32_t index)
uint32_t device_count = 0; uint32_t device_count = 0;
ssize_t cnt; ssize_t cnt;
libusb_init(&ctx); r = libusb_init(&ctx);
if(r < 0)
return "";
cnt = libusb_get_device_list(ctx, &list); cnt = libusb_get_device_list(ctx, &list);
@ -1373,7 +1377,9 @@ int rtlsdr_get_device_usb_strings(uint32_t index, char *manufact,
uint32_t device_count = 0; uint32_t device_count = 0;
ssize_t cnt; ssize_t cnt;
libusb_init(&ctx); r = libusb_init(&ctx);
if(r < 0)
return r;
cnt = libusb_get_device_list(ctx, &list); cnt = libusb_get_device_list(ctx, &list);
@ -1447,7 +1453,11 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
memset(dev, 0, sizeof(rtlsdr_dev_t)); memset(dev, 0, sizeof(rtlsdr_dev_t));
memcpy(dev->fir, fir_default, sizeof(fir_default)); memcpy(dev->fir, fir_default, sizeof(fir_default));
libusb_init(&dev->ctx); r = libusb_init(&dev->ctx);
if(r < 0){
free(dev);
return -1;
}
dev->dev_lost = 1; dev->dev_lost = 1;

Loading…
Cancel
Save