From 1451ba9a4629ca9bd95b98223caf5cf2eca5051d Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 10 Sep 2017 23:35:55 +0200 Subject: [PATCH] fix crash if a JsonReply times out but we still get a result afterwards --- libguh/devicemanager.cpp | 4 ++++ server/jsonrpc/actionhandler.cpp | 4 +++- server/jsonrpc/devicehandler.cpp | 4 ++++ server/jsonrpc/jsonhandler.cpp | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libguh/devicemanager.cpp b/libguh/devicemanager.cpp index 7c59691d..fb197501 100644 --- a/libguh/devicemanager.cpp +++ b/libguh/devicemanager.cpp @@ -1170,6 +1170,10 @@ void DeviceManager::startMonitoringAutoDevices() void DeviceManager::slotDevicesDiscovered(const DeviceClassId &deviceClassId, const QList deviceDescriptors) { DevicePlugin *plugin = static_cast(sender()); + if (!m_discoveringPlugins.contains(plugin)) { + qWarning(dcDeviceManager()) << "Received a devicesDiscovered signal from" << plugin->pluginName() << "but did not expect it. Ignoring."; + return; + } m_discoveringPlugins.removeOne(plugin); foreach (const DeviceDescriptor &descriptor, deviceDescriptors) { diff --git a/server/jsonrpc/actionhandler.cpp b/server/jsonrpc/actionhandler.cpp index c848f918..57720b59 100644 --- a/server/jsonrpc/actionhandler.cpp +++ b/server/jsonrpc/actionhandler.cpp @@ -83,7 +83,9 @@ JsonReply* ActionHandler::ExecuteAction(const QVariantMap ¶ms) DeviceManager::DeviceError status = GuhCore::instance()->executeAction(action); if (status == DeviceManager::DeviceErrorAsync) { JsonReply *reply = createAsyncReply("ExecuteAction"); - m_asyncActionExecutions.insert(action.id(), reply); + ActionId id = action.id(); + connect(reply, &JsonReply::finished, [this, id](){ m_asyncActionExecutions.remove(id); }); + m_asyncActionExecutions.insert(id, reply); return reply; } diff --git a/server/jsonrpc/devicehandler.cpp b/server/jsonrpc/devicehandler.cpp index 9b03ffd5..c139eef1 100644 --- a/server/jsonrpc/devicehandler.cpp +++ b/server/jsonrpc/devicehandler.cpp @@ -336,6 +336,7 @@ JsonReply *DeviceHandler::GetDiscoveredDevices(const QVariantMap ¶ms) const DeviceManager::DeviceError status = GuhCore::instance()->deviceManager()->discoverDevices(deviceClassId, discoveryParams); if (status == DeviceManager::DeviceErrorAsync ) { JsonReply *reply = createAsyncReply("GetDiscoveredDevices"); + connect(reply, &JsonReply::finished, [this, deviceClassId](){ m_discoverRequests.remove(deviceClassId); }); m_discoverRequests.insert(deviceClassId, reply); return reply; } @@ -398,6 +399,7 @@ JsonReply* DeviceHandler::AddConfiguredDevice(const QVariantMap ¶ms) switch (status) { case DeviceManager::DeviceErrorAsync: { JsonReply *asyncReply = createAsyncReply("AddConfiguredDevice"); + connect(asyncReply, &JsonReply::finished, [this, newDeviceId](){ m_asynDeviceAdditions.remove(newDeviceId); }); m_asynDeviceAdditions.insert(newDeviceId, asyncReply); return asyncReply; } @@ -446,6 +448,7 @@ JsonReply *DeviceHandler::ConfirmPairing(const QVariantMap ¶ms) JsonReply *reply = 0; if (status == DeviceManager::DeviceErrorAsync) { reply = createAsyncReply("ConfirmPairing"); + connect(reply, &JsonReply::finished, [this, pairingTransactionId](){ m_asyncPairingRequests.remove(pairingTransactionId); }); m_asyncPairingRequests.insert(pairingTransactionId, reply); return reply; } @@ -492,6 +495,7 @@ JsonReply *DeviceHandler::ReconfigureDevice(const QVariantMap ¶ms) if (status == DeviceManager::DeviceErrorAsync) { JsonReply *asyncReply = createAsyncReply("ReconfigureDevice"); + connect(asyncReply, &JsonReply::finished, [this, deviceId](){ m_asynDeviceEditAdditions.remove(deviceId); }); m_asynDeviceEditAdditions.insert(deviceId, asyncReply); return asyncReply; } diff --git a/server/jsonrpc/jsonhandler.cpp b/server/jsonrpc/jsonhandler.cpp index 54f00295..9bb16296 100644 --- a/server/jsonrpc/jsonhandler.cpp +++ b/server/jsonrpc/jsonhandler.cpp @@ -325,7 +325,7 @@ void JsonReply::setCommandId(int commandId) m_commandId = commandId; } -/*! Start the timeout timer for this \l{JsonReply}. The default timeout is 10 seconds. */ +/*! Start the timeout timer for this \l{JsonReply}. The default timeout is 15 seconds. */ void JsonReply::startWait() { m_timeout.start(15000);