From 862d205b6c2ef29f464231b7f7db63bf2cbb07ec Mon Sep 17 00:00:00 2001 From: Jannis Voelker Date: Fri, 4 May 2018 13:47:12 +0200 Subject: 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 --- src/plugins/opcua/freeopcua/qfreeopcuaworker.cpp | 4 ++-- 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; } -- cgit v1.2.3