diff --git a/src/main.cpp b/src/main.cpp index 67437881..1acc4b06 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2855,6 +2855,9 @@ void MainFrame::stopRxStream() if (m_txThread) { + m_txThread->terminateThread(); + m_txThread->Wait(); + if (txInSoundDevice) { txInSoundDevice->stop(); @@ -2867,15 +2870,15 @@ void MainFrame::stopRxStream() txOutSoundDevice.reset(); } - m_txThread->terminateThread(); - m_txThread->Wait(); - delete m_txThread; m_txThread = nullptr; } if (m_rxThread) { + m_rxThread->terminateThread(); + m_rxThread->Wait(); + if (rxInSoundDevice) { rxInSoundDevice->stop(); @@ -2888,9 +2891,6 @@ void MainFrame::stopRxStream() rxOutSoundDevice.reset(); } - m_rxThread->terminateThread(); - m_rxThread->Wait(); - delete m_txThread; m_rxThread = nullptr; } diff --git a/src/pipeline/TxRxThread.cpp b/src/pipeline/TxRxThread.cpp index 9d830647..b94336fe 100644 --- a/src/pipeline/TxRxThread.cpp +++ b/src/pipeline/TxRxThread.cpp @@ -515,7 +515,8 @@ void* TxRxThread::Entry() void TxRxThread::OnExit() { - // No actions required for exit. + // Free allocated buffer. + inputSamples_ = nullptr; } void TxRxThread::terminateThread() diff --git a/src/pipeline/TxRxThread.h b/src/pipeline/TxRxThread.h index 2593a89f..39a23a9a 100644 --- a/src/pipeline/TxRxThread.h +++ b/src/pipeline/TxRxThread.h @@ -58,6 +58,12 @@ public: new short[std::max(inputSampleRate_, outputSampleRate_)], std::default_delete()); } + + virtual ~TxRxThread() + { + // Free allocated buffer + inputSamples_ = nullptr; + } // thread execution starts here void *Entry();