From 2a95d05631bfc086b671a5a61fdaa97d65d3d0bd Mon Sep 17 00:00:00 2001 From: Eoin Mcloughlin Date: Wed, 7 Oct 2015 20:17:38 +0100 Subject: [PATCH 1/2] Fix crash when rtlsdr_open fails --- src/sdr/SDRThread.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sdr/SDRThread.cpp b/src/sdr/SDRThread.cpp index 81f4cc0..5ee8080 100644 --- a/src/sdr/SDRThread.cpp +++ b/src/sdr/SDRThread.cpp @@ -41,8 +41,12 @@ int SDRThread::enumerate_rtl(std::vector *devs) { deviceProduct = product; deviceManufacturer = manufact; - rtlsdr_dev_t *devTest; - rtlsdr_open(&devTest, i); + rtlsdr_dev_t *devTest = nullptr; + if(rtlsdr_open(&devTest, i) < 0) + { + std::cout << "\tFailed to open device " << i << std::endl; + continue; + } std::cout << "\t Tuner type: "; switch (rtlsdr_get_tuner_type(devTest)) { From 0b10a5b30c6496189f7ad6d0c47f50a8b0a3082c Mon Sep 17 00:00:00 2001 From: Eoin Mcloughlin Date: Wed, 7 Oct 2015 20:18:29 +0100 Subject: [PATCH 2/2] Fix crash in AudioThread::setActive If AudioThread::run() hasn't been called yet, we can dereference a null inputQueue --- src/audio/AudioThread.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/audio/AudioThread.cpp b/src/audio/AudioThread.cpp index 789e016..3ea1bfb 100644 --- a/src/audio/AudioThread.cpp +++ b/src/audio/AudioThread.cpp @@ -428,7 +428,7 @@ bool AudioThread::isActive() { void AudioThread::setActive(bool state) { AudioThreadInput *dummy; - if (state && !active) { + if (state && !active && inputQueue) { while (!inputQueue->empty()) { // flush queue inputQueue->pop(dummy); if (dummy) { @@ -438,10 +438,12 @@ void AudioThread::setActive(bool state) { deviceController[parameters.deviceId]->bindThread(this); } else if (!state && active) { deviceController[parameters.deviceId]->removeThread(this); - while (!inputQueue->empty()) { // flush queue - inputQueue->pop(dummy); - if (dummy) { - dummy->decRefCount(); + if(inputQueue) { + while (!inputQueue->empty()) { // flush queue + inputQueue->pop(dummy); + if (dummy) { + dummy->decRefCount(); + } } } }