Hi All,
In case buffer allocation fails there will be a crash.
I suggest something like this in rtlsdr_read_async:
if(_rtlsdr_alloc_async_buffers(dev) < 0) { _rtlsdr_free_async_buffers(dev); return -1; }
The function _rtlsdr_alloc_async_buffers needs tests for malloc returning NULL with an appropriate return of an error code to make the above work.
Immediately below the suggested change it may be a good idea to introduce a small delay. Without this delay libusb-1.0 crashes under Windows if the sampling rate is high and the computer is a bit slow:
for(i = 0; i < dev->xfer_buf_num; ++i) { #ifdef _WIN32 Sleep(1); #else usleep(1000); #endif
libusb_fill_bulk_transfer(dev->xfer[i], dev->devh, 0x81,
A little further down one more change is desireable: /*fprintf(stderr, "handle_events returned: %d\n", r); if (r == LIBUSB_ERROR_INTERRUPTED || r==-1) /* stray
The error code -1 occurs frequently but the data supplied to the application callback is perfectly OK. On faster computers there is never any error, but with a Centrino Duo at 900 kHz there are 2 or 3 errors (-1) for each proper return in case small buffers are selected.
Regards
Leif