mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-21 15:51:47 -05:00
Merge pull request #2330 from srcejon/fix_2315
Fix a few memory leaks and race conditions
This commit is contained in:
commit
7bc6210b64
@ -79,6 +79,7 @@ FreeDVDemod::FreeDVDemod(DeviceAPI *deviceAPI) :
|
|||||||
|
|
||||||
FreeDVDemod::~FreeDVDemod()
|
FreeDVDemod::~FreeDVDemod()
|
||||||
{
|
{
|
||||||
|
stop();
|
||||||
QObject::disconnect(
|
QObject::disconnect(
|
||||||
m_networkManager,
|
m_networkManager,
|
||||||
&QNetworkAccessManager::finished,
|
&QNetworkAccessManager::finished,
|
||||||
|
@ -176,6 +176,8 @@ FreeDVDemodSink::~FreeDVDemodSink()
|
|||||||
{
|
{
|
||||||
delete SSBFilter;
|
delete SSBFilter;
|
||||||
delete[] m_SSBFilterBuffer;
|
delete[] m_SSBFilterBuffer;
|
||||||
|
delete[] m_speechOut;
|
||||||
|
delete[] m_modIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeDVDemodSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
|
void FreeDVDemodSink::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end)
|
||||||
@ -449,7 +451,7 @@ void FreeDVDemodSink::applyFreeDVMode(FreeDVDemodSettings::FreeDVMode mode)
|
|||||||
freedv_set_ext_vco(m_freeDV, 0);
|
freedv_set_ext_vco(m_freeDV, 0);
|
||||||
freedv_set_sync(m_freeDV, FREEDV_SYNC_MANUAL);
|
freedv_set_sync(m_freeDV, FREEDV_SYNC_MANUAL);
|
||||||
|
|
||||||
int nSpeechSamples = freedv_get_n_speech_samples(m_freeDV);
|
int nSpeechSamples = freedv_get_n_max_speech_samples(m_freeDV);
|
||||||
int nMaxModemSamples = freedv_get_n_max_modem_samples(m_freeDV);
|
int nMaxModemSamples = freedv_get_n_max_modem_samples(m_freeDV);
|
||||||
int Fs = freedv_get_modem_sample_rate(m_freeDV);
|
int Fs = freedv_get_modem_sample_rate(m_freeDV);
|
||||||
int Rs = freedv_get_modem_symbol_rate(m_freeDV);
|
int Rs = freedv_get_modem_symbol_rate(m_freeDV);
|
||||||
|
@ -187,39 +187,41 @@ void DSPEngine::removeLastDeviceMIMOEngine()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QThread * DSPEngine::removeDeviceEngineAt(int deviceIndex)
|
QThread *DSPEngine::getDeviceEngineThread(int deviceIndex)
|
||||||
{
|
{
|
||||||
if (deviceIndex >= m_deviceEngineReferences.size()) {
|
if (deviceIndex >= m_deviceEngineReferences.size()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
} else {
|
||||||
|
return m_deviceEngineReferences[deviceIndex].m_thread;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QThread *deviceThread = nullptr;
|
void DSPEngine::removeDeviceEngineAt(int deviceIndex)
|
||||||
|
{
|
||||||
|
if (deviceIndex >= m_deviceEngineReferences.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 0) // source
|
if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 0) // source
|
||||||
{
|
{
|
||||||
DSPDeviceSourceEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSourceEngine;
|
DSPDeviceSourceEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSourceEngine;
|
||||||
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
|
m_deviceEngineReferences[deviceIndex].m_thread->exit();
|
||||||
deviceThread->exit();
|
|
||||||
m_deviceSourceEngines.removeAll(deviceEngine);
|
m_deviceSourceEngines.removeAll(deviceEngine);
|
||||||
}
|
}
|
||||||
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 1) // sink
|
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 1) // sink
|
||||||
{
|
{
|
||||||
DSPDeviceSinkEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSinkEngine;
|
DSPDeviceSinkEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceSinkEngine;
|
||||||
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
|
m_deviceEngineReferences[deviceIndex].m_thread->exit();
|
||||||
deviceThread->exit();
|
|
||||||
m_deviceSinkEngines.removeAll(deviceEngine);
|
m_deviceSinkEngines.removeAll(deviceEngine);
|
||||||
}
|
}
|
||||||
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 2) // MIMO
|
else if (m_deviceEngineReferences[deviceIndex].m_deviceEngineType == 2) // MIMO
|
||||||
{
|
{
|
||||||
DSPDeviceMIMOEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceMIMOEngine;
|
DSPDeviceMIMOEngine *deviceEngine = m_deviceEngineReferences[deviceIndex].m_deviceMIMOEngine;
|
||||||
deviceThread = m_deviceEngineReferences[deviceIndex].m_thread;
|
m_deviceEngineReferences[deviceIndex].m_thread->exit();
|
||||||
deviceThread->exit();
|
|
||||||
m_deviceMIMOEngines.removeAll(deviceEngine);
|
m_deviceMIMOEngines.removeAll(deviceEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_deviceEngineReferences.removeAt(deviceIndex);
|
m_deviceEngineReferences.removeAt(deviceIndex);
|
||||||
|
|
||||||
return deviceThread;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DSPEngine::createFFTFactory(const QString& fftWisdomFileName)
|
void DSPEngine::createFFTFactory(const QString& fftWisdomFileName)
|
||||||
|
@ -53,7 +53,8 @@ public:
|
|||||||
DSPDeviceMIMOEngine *addDeviceMIMOEngine();
|
DSPDeviceMIMOEngine *addDeviceMIMOEngine();
|
||||||
void removeLastDeviceMIMOEngine();
|
void removeLastDeviceMIMOEngine();
|
||||||
|
|
||||||
QThread *removeDeviceEngineAt(int deviceIndex);
|
QThread *getDeviceEngineThread(int deviceIndex);
|
||||||
|
void removeDeviceEngineAt(int deviceIndex);
|
||||||
|
|
||||||
AudioDeviceManager *getAudioDeviceManager() { return &m_audioDeviceManager; }
|
AudioDeviceManager *getAudioDeviceManager() { return &m_audioDeviceManager; }
|
||||||
|
|
||||||
|
@ -778,11 +778,20 @@ void RemoveDeviceSetFSM::removeUI()
|
|||||||
void RemoveDeviceSetFSM::stopEngine()
|
void RemoveDeviceSetFSM::stopEngine()
|
||||||
{
|
{
|
||||||
qDebug() << "RemoveDeviceSetFSM::stopEngine";
|
qDebug() << "RemoveDeviceSetFSM::stopEngine";
|
||||||
QThread *thread = m_mainWindow->m_dspEngine->removeDeviceEngineAt(m_deviceSetIndex);
|
QThread *thread = m_mainWindow->m_dspEngine->getDeviceEngineThread(m_deviceSetIndex);
|
||||||
if (thread && !thread->isFinished()) // FIXME: Is there a race condition here? We might need to connect before calling thread->exit
|
|
||||||
|
if (thread)
|
||||||
{
|
{
|
||||||
|
bool finished = thread->isFinished();
|
||||||
|
|
||||||
|
if (!finished) {
|
||||||
connect(thread, &QThread::finished, m_mainWindow, &MainWindow::engineStopped);
|
connect(thread, &QThread::finished, m_mainWindow, &MainWindow::engineStopped);
|
||||||
}
|
}
|
||||||
|
m_mainWindow->m_dspEngine->removeDeviceEngineAt(m_deviceSetIndex);
|
||||||
|
if (finished) {
|
||||||
|
emit m_mainWindow->engineStopped();
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit m_mainWindow->engineStopped();
|
emit m_mainWindow->engineStopped();
|
||||||
@ -801,12 +810,20 @@ void RemoveDeviceSetFSM::removeDeviceSet()
|
|||||||
|
|
||||||
DeviceAPI *deviceAPI = m_deviceUISet->m_deviceAPI;
|
DeviceAPI *deviceAPI = m_deviceUISet->m_deviceAPI;
|
||||||
delete m_deviceUISet;
|
delete m_deviceUISet;
|
||||||
if (m_deviceSourceEngine) {
|
if (m_deviceSourceEngine)
|
||||||
|
{
|
||||||
delete deviceAPI->getSampleSource();
|
delete deviceAPI->getSampleSource();
|
||||||
} else if (m_deviceSinkEngine) {
|
delete m_deviceSourceEngine;
|
||||||
|
}
|
||||||
|
else if (m_deviceSinkEngine)
|
||||||
|
{
|
||||||
delete deviceAPI->getSampleSink();
|
delete deviceAPI->getSampleSink();
|
||||||
} else {
|
delete m_deviceSinkEngine;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
delete deviceAPI->getSampleMIMO();
|
delete deviceAPI->getSampleMIMO();
|
||||||
|
delete m_deviceMIMOEngine;
|
||||||
}
|
}
|
||||||
delete deviceAPI;
|
delete deviceAPI;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user