aboutsummaryrefslogtreecommitdiffstats
path: root/src/librtlsdr.c
diff options
context:
space:
mode:
authorHoernchen <la@tfc-server.de>2015-06-09 01:48:55 +0200
committerHoernchen <la@tfc-server.de>2015-06-09 01:53:23 +0200
commite3c03f738f5aef4dc51e2b741fbdb542b9cc1bb1 (patch)
tree6754055dbc97a604dc065a75560eeaa4f36dd1c7 /src/librtlsdr.c
parent5c376fc79c919c0e16a832328c92f5213f0cdd54 (diff)
lib: check for libusb init failure
Diffstat (limited to 'src/librtlsdr.c')
-rw-r--r--src/librtlsdr.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index 0650606..cdf1ca9 100644
--- a/src/librtlsdr.c
+++ b/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)
{
- int i;
+ int i,r;
libusb_context *ctx;
libusb_device **list;
uint32_t device_count = 0;
struct libusb_device_descriptor dd;
ssize_t cnt;
- libusb_init(&ctx);
+ r = libusb_init(&ctx);
+ if(r < 0)
+ return 0;
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)
{
- int i;
+ int i,r;
libusb_context *ctx;
libusb_device **list;
struct libusb_device_descriptor dd;
@@ -1333,7 +1335,9 @@ const char *rtlsdr_get_device_name(uint32_t index)
uint32_t device_count = 0;
ssize_t cnt;
- libusb_init(&ctx);
+ r = libusb_init(&ctx);
+ if(r < 0)
+ return "";
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;
ssize_t cnt;
- libusb_init(&ctx);
+ r = libusb_init(&ctx);
+ if(r < 0)
+ return r;
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));
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;