summaryrefslogtreecommitdiffstats
path: root/src/mqtt/qmqttclient.cpp
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@qt.io>2023-03-10 11:03:55 +0100
committerMaurice Kalinowski <maurice.kalinowski@qt.io>2023-03-30 11:54:01 +0100
commitc04b21a2dcce46047bc08c9a833ca78ee43ee41c (patch)
treecd8475825b0d37dcd8755fd38cc37c7e89c8af84 /src/mqtt/qmqttclient.cpp
parentdfbb02ed03dc1a68c4a1c71df0afcdfcb9034d1c (diff)
Windows: Fix crash on QMqttClient destruction
On Windows, sending DISCONNECT might return data before the QMqttConnection is destroyed, causing it to invoke on bogus QMqttClient members. Hence, set a flag to avoid this event, but still aim to send a disconnect to the broker to nicely quit. Fixes: QTBUG-111846 Pick-to: 6.5 6.4 6.2 Change-Id: Ia94865c9b404ecbd814150c313679aa10b3f6aa0 Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Diffstat (limited to 'src/mqtt/qmqttclient.cpp')
-rw-r--r--src/mqtt/qmqttclient.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mqtt/qmqttclient.cpp b/src/mqtt/qmqttclient.cpp
index 6e15f72..7191684 100644
--- a/src/mqtt/qmqttclient.cpp
+++ b/src/mqtt/qmqttclient.cpp
@@ -326,7 +326,11 @@ QMqttClient::QMqttClient(QObject *parent) : QObject(*(new QMqttClientPrivate(thi
*/
QMqttClient::~QMqttClient()
{
- disconnectFromHost();
+ Q_D(QMqttClient);
+ if (d->m_connection.internalState() == QMqttConnection::BrokerConnected) {
+ d->m_connection.setClientDestruction();
+ disconnectFromHost();
+ }
}
/*!
@@ -575,6 +579,7 @@ void QMqttClient::disconnectFromHost()
switch (d->m_connection.internalState()) {
case QMqttConnection::BrokerConnected:
+ case QMqttConnection::ClientDestruction:
d->m_connection.sendControlDisconnect();
break;
case QMqttConnection::BrokerDisconnected: