diff options
author | Jannis Voelker <jannis.voelker@basyskom.com> | 2018-05-04 13:47:12 +0200 |
---|---|---|
committer | Jannis Völker <jannis.voelker@basyskom.com> | 2018-05-09 07:26:08 +0000 |
commit | 862d205b6c2ef29f464231b7f7db63bf2cbb07ec (patch) | |
tree | d1a1279561aac4217d0d9b8098a416eeb85d71d6 | |
parent | a6a5d46aeb926f4fece9d25177b1dd8230d885be (diff) |
Fix possible crash in the client state handling
The client state change callback may be called after the
QOpcUaClientImpl associated with the backend has been destroyed.
The signal should not be emitted by directly calling the method
of the QOpcUaClientImpl because the backend runs in a separate
thread.
Change-Id: I6417987bb438ffa3db3d8e68cbfcafe220e16c1c
Reviewed-by: Frank Meerkoetter <frank.meerkoetter@basyskom.com>
-rw-r--r-- | src/plugins/opcua/freeopcua/qfreeopcuaworker.cpp | 4 | ||||
-rw-r--r-- | src/plugins/opcua/open62541/qopen62541backend.cpp | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/plugins/opcua/freeopcua/qfreeopcuaworker.cpp b/src/plugins/opcua/freeopcua/qfreeopcuaworker.cpp index 2f6ebd6..3acdf8b 100644 --- a/src/plugins/opcua/freeopcua/qfreeopcuaworker.cpp +++ b/src/plugins/opcua/freeopcua/qfreeopcuaworker.cpp @@ -96,7 +96,7 @@ void QFreeOpcUaWorker::asyncDisconnectFromEndpoint() { try { Disconnect(); - emit m_client->stateAndOrErrorChanged(QOpcUaClient::Disconnected, QOpcUaClient::NoError); + emit stateAndOrErrorChanged(QOpcUaClient::Disconnected, QOpcUaClient::NoError); return; } catch (const std::exception &ex) { qCWarning(QT_OPCUA_PLUGINS_FREEOPCUA) << "Could not disconnect from endpoint:" << ex.what(); @@ -105,7 +105,7 @@ void QFreeOpcUaWorker::asyncDisconnectFromEndpoint() qDeleteAll(m_subscriptions); m_subscriptions.clear(); - emit m_client->stateAndOrErrorChanged(QOpcUaClient::Disconnected, QOpcUaClient::UnknownError); + emit stateAndOrErrorChanged(QOpcUaClient::Disconnected, QOpcUaClient::UnknownError); } void QFreeOpcUaWorker::browseChildren(uintptr_t handle, OpcUa::NodeId id, QOpcUa::ReferenceTypeId referenceType, QOpcUa::NodeClasses nodeClassMask) diff --git a/src/plugins/opcua/open62541/qopen62541backend.cpp b/src/plugins/opcua/open62541/qopen62541backend.cpp index 9fcd8d3..15d1166 100644 --- a/src/plugins/opcua/open62541/qopen62541backend.cpp +++ b/src/plugins/opcua/open62541/qopen62541backend.cpp @@ -427,7 +427,7 @@ static void clientStateCallback(UA_Client *client, UA_ClientState state) return; if (state == UA_CLIENTSTATE_DISCONNECTED) { - emit backend->m_clientImpl->stateAndOrErrorChanged(QOpcUaClient::Disconnected, QOpcUaClient::ConnectionError); + emit backend->stateAndOrErrorChanged(QOpcUaClient::Disconnected, QOpcUaClient::ConnectionError); backend->m_useStateCallback = false; } } @@ -455,7 +455,8 @@ void Open62541AsyncBackend::connectToEndpoint(const QUrl &url) UA_Client_delete(m_uaclient); m_uaclient = nullptr; QOpcUaClient::ClientError error = ret == UA_STATUSCODE_BADUSERACCESSDENIED ? QOpcUaClient::AccessDenied : QOpcUaClient::UnknownError; - emit m_clientImpl->stateAndOrErrorChanged(QOpcUaClient::Disconnected, error); + + emit stateAndOrErrorChanged(QOpcUaClient::Disconnected, error); qCWarning(QT_OPCUA_PLUGINS_OPEN62541) << "Open62541: Failed to connect"; return; } |