From 8f3ef9e76d92916056ae6ddeb7b6f95e0599c077 Mon Sep 17 00:00:00 2001 From: f4exb Date: Wed, 14 Feb 2018 13:40:34 +0100 Subject: [PATCH] Main Window: fixed memory leak with remove last device --- sdrbase/webapi/webapiadapterinterface.h | 1 + sdrbase/webapi/webapirequestmapper.cpp | 5 +++-- sdrgui/mainwindow.cpp | 2 ++ sdrgui/webapi/webapiadaptergui.cpp | 27 ++++++++++++++----------- sdrgui/webapi/webapiadaptergui.h | 1 + sdrsrv/webapi/webapiadaptersrv.cpp | 26 ++++++++++++++---------- sdrsrv/webapi/webapiadaptersrv.h | 1 + 7 files changed, 38 insertions(+), 25 deletions(-) diff --git a/sdrbase/webapi/webapiadapterinterface.h b/sdrbase/webapi/webapiadapterinterface.h index a1309951f..914a2abac 100644 --- a/sdrbase/webapi/webapiadapterinterface.h +++ b/sdrbase/webapi/webapiadapterinterface.h @@ -370,6 +370,7 @@ public: */ virtual int devicesetDevicePut( int deviceSetIndex __attribute__((unused)), + SWGSDRangel::SWGDeviceListItem& query __attribute__((unused)), SWGSDRangel::SWGDeviceListItem& response __attribute__((unused)), SWGSDRangel::SWGErrorResponse& error) { diff --git a/sdrbase/webapi/webapirequestmapper.cpp b/sdrbase/webapi/webapirequestmapper.cpp index a6efe4aa5..5e4399da2 100644 --- a/sdrbase/webapi/webapirequestmapper.cpp +++ b/sdrbase/webapi/webapirequestmapper.cpp @@ -868,11 +868,12 @@ void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qt if (parseJsonBody(jsonStr, jsonObject, response)) { + SWGSDRangel::SWGDeviceListItem query; SWGSDRangel::SWGDeviceListItem normalResponse; - if (validateDeviceListItem(normalResponse, jsonObject)) + if (validateDeviceListItem(query, jsonObject)) { - int status = m_adapter->devicesetDevicePut(deviceSetIndex, normalResponse, errorResponse); + int status = m_adapter->devicesetDevicePut(deviceSetIndex, query, normalResponse, errorResponse); response.setStatus(status); if (status/100 == 2) { diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 017c0cb07..79a19e913 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -395,6 +395,7 @@ void MainWindow::removeLastDevice() ui->tabInputsView->setTabToolTip(i, m_deviceWidgetTabs[i].displayName); } + delete m_deviceUIs.back()->m_deviceSourceAPI; delete m_deviceUIs.back(); lastDeviceEngine->stop(); @@ -434,6 +435,7 @@ void MainWindow::removeLastDevice() ui->tabInputsView->setTabToolTip(i, m_deviceWidgetTabs[i].displayName); } + delete m_deviceUIs.back()->m_deviceSinkAPI; delete m_deviceUIs.back(); lastDeviceEngine->stop(); diff --git a/sdrgui/webapi/webapiadaptergui.cpp b/sdrgui/webapi/webapiadaptergui.cpp index c43fd8c06..3b6b386ba 100644 --- a/sdrgui/webapi/webapiadaptergui.cpp +++ b/sdrgui/webapi/webapiadaptergui.cpp @@ -696,6 +696,7 @@ int WebAPIAdapterGUI::devicesetFocusPatch( int WebAPIAdapterGUI::devicesetDevicePut( int deviceSetIndex, + SWGSDRangel::SWGDeviceListItem& query, SWGSDRangel::SWGDeviceListItem& response, SWGSDRangel::SWGErrorResponse& error) { @@ -703,46 +704,48 @@ int WebAPIAdapterGUI::devicesetDevicePut( { DeviceUISet *deviceSet = m_mainWindow.m_deviceUIs[deviceSetIndex]; - if ((response.getTx() == 0) && (deviceSet->m_deviceSinkEngine)) + if ((query.getTx() == 0) && (deviceSet->m_deviceSinkEngine)) { + error.init(); *error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch"); return 404; } - if ((response.getTx() != 0) && (deviceSet->m_deviceSourceEngine)) + if ((query.getTx() != 0) && (deviceSet->m_deviceSourceEngine)) { + error.init(); *error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch"); return 404; } - int nbSamplingDevices = response.getTx() != 0 ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices(); - int tx = response.getTx(); + int nbSamplingDevices = query.getTx() != 0 ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices(); + int tx = query.getTx(); for (int i = 0; i < nbSamplingDevices; i++) { - PluginInterface::SamplingDevice samplingDevice = response.getTx() ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i); + PluginInterface::SamplingDevice samplingDevice = query.getTx() ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i); - if (response.getDisplayedName() && (*response.getDisplayedName() != samplingDevice.displayedName)) { + if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice.displayedName)) { continue; } - if (response.getHwType() && (*response.getHwType() != samplingDevice.hardwareId)) { + if (query.getHwType() && (*query.getHwType() != samplingDevice.hardwareId)) { continue; } - if ((response.getSequence() >= 0) && (response.getSequence() != samplingDevice.sequence)) { + if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice.sequence)) { continue; } - if (response.getSerial() && (*response.getSerial() != samplingDevice.serial)) { + if (query.getSerial() && (*query.getSerial() != samplingDevice.serial)) { continue; } - if ((response.getStreamIndex() >= 0) && (response.getStreamIndex() != samplingDevice.deviceItemIndex)) { + if ((query.getStreamIndex() >= 0) && (query.getStreamIndex() != samplingDevice.deviceItemIndex)) { continue; } - MainWindow::MsgSetDevice *msg = MainWindow::MsgSetDevice::create(deviceSetIndex, i, response.getTx() != 0); + MainWindow::MsgSetDevice *msg = MainWindow::MsgSetDevice::create(deviceSetIndex, i, query.getTx() != 0); m_mainWindow.m_inputMessageQueue.push(msg); response.init(); @@ -759,6 +762,7 @@ int WebAPIAdapterGUI::devicesetDevicePut( return 202; } + error.init(); *error.getMessage() = QString("Device not found"); return 404; } @@ -766,7 +770,6 @@ int WebAPIAdapterGUI::devicesetDevicePut( { error.init(); *error.getMessage() = QString("There is no device set with index %1").arg(deviceSetIndex); - return 404; } } diff --git a/sdrgui/webapi/webapiadaptergui.h b/sdrgui/webapi/webapiadaptergui.h index d2f62a252..18a91ae5b 100644 --- a/sdrgui/webapi/webapiadaptergui.h +++ b/sdrgui/webapi/webapiadaptergui.h @@ -127,6 +127,7 @@ public: virtual int devicesetDevicePut( int deviceSetIndex, + SWGSDRangel::SWGDeviceListItem& query, SWGSDRangel::SWGDeviceListItem& response, SWGSDRangel::SWGErrorResponse& error); diff --git a/sdrsrv/webapi/webapiadaptersrv.cpp b/sdrsrv/webapi/webapiadaptersrv.cpp index 62efda069..acb01fe0c 100644 --- a/sdrsrv/webapi/webapiadaptersrv.cpp +++ b/sdrsrv/webapi/webapiadaptersrv.cpp @@ -797,6 +797,7 @@ int WebAPIAdapterSrv::devicesetFocusPatch( int WebAPIAdapterSrv::devicesetDevicePut( int deviceSetIndex, + SWGSDRangel::SWGDeviceListItem& query, SWGSDRangel::SWGDeviceListItem& response, SWGSDRangel::SWGErrorResponse& error) { @@ -804,46 +805,48 @@ int WebAPIAdapterSrv::devicesetDevicePut( { DeviceSet *deviceSet = m_mainCore.m_deviceSets[deviceSetIndex]; - if ((response.getTx() == 0) && (deviceSet->m_deviceSinkEngine)) + if ((query.getTx() == 0) && (deviceSet->m_deviceSinkEngine)) { + error.init(); *error.getMessage() = QString("Device type (Rx) and device set type (Tx) mismatch"); return 404; } - if ((response.getTx() != 0) && (deviceSet->m_deviceSourceEngine)) + if ((query.getTx() != 0) && (deviceSet->m_deviceSourceEngine)) { + error.init(); *error.getMessage() = QString("Device type (Tx) and device set type (Rx) mismatch"); return 404; } - int nbSamplingDevices = response.getTx() != 0 ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices(); - int tx = response.getTx(); + int nbSamplingDevices = query.getTx() != 0 ? DeviceEnumerator::instance()->getNbTxSamplingDevices() : DeviceEnumerator::instance()->getNbRxSamplingDevices(); + int tx = query.getTx(); for (int i = 0; i < nbSamplingDevices; i++) { - PluginInterface::SamplingDevice samplingDevice = response.getTx() ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i); + PluginInterface::SamplingDevice samplingDevice = query.getTx() ? DeviceEnumerator::instance()->getTxSamplingDevice(i) : DeviceEnumerator::instance()->getRxSamplingDevice(i); - if (response.getDisplayedName() && (*response.getDisplayedName() != samplingDevice.displayedName)) { + if (query.getDisplayedName() && (*query.getDisplayedName() != samplingDevice.displayedName)) { continue; } - if (response.getHwType() && (*response.getHwType() != samplingDevice.hardwareId)) { + if (query.getHwType() && (*query.getHwType() != samplingDevice.hardwareId)) { continue; } - if ((response.getSequence() >= 0) && (response.getSequence() != samplingDevice.sequence)) { + if ((query.getSequence() >= 0) && (query.getSequence() != samplingDevice.sequence)) { continue; } - if (response.getSerial() && (*response.getSerial() != samplingDevice.serial)) { + if (query.getSerial() && (*query.getSerial() != samplingDevice.serial)) { continue; } - if ((response.getStreamIndex() >= 0) && (response.getStreamIndex() != samplingDevice.deviceItemIndex)) { + if ((query.getStreamIndex() >= 0) && (query.getStreamIndex() != samplingDevice.deviceItemIndex)) { continue; } - MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, response.getTx() != 0); + MainCore::MsgSetDevice *msg = MainCore::MsgSetDevice::create(deviceSetIndex, i, query.getTx() != 0); m_mainCore.m_inputMessageQueue.push(msg); response.init(); @@ -860,6 +863,7 @@ int WebAPIAdapterSrv::devicesetDevicePut( return 202; } + error.init(); *error.getMessage() = QString("Device not found"); return 404; } diff --git a/sdrsrv/webapi/webapiadaptersrv.h b/sdrsrv/webapi/webapiadaptersrv.h index 5205ba498..e8240bafa 100644 --- a/sdrsrv/webapi/webapiadaptersrv.h +++ b/sdrsrv/webapi/webapiadaptersrv.h @@ -138,6 +138,7 @@ public: virtual int devicesetDevicePut( int deviceSetIndex, + SWGSDRangel::SWGDeviceListItem& query, SWGSDRangel::SWGDeviceListItem& response, SWGSDRangel::SWGErrorResponse& error);