1
0
mirror of https://github.com/qt/qtmqtt.git synced 2026-10-25 16:16:26 +00:00

[BiC] Fix dangling pointer dereferencing when destroying QMqttClient

when QMqttClient gets destroyed in Connected state, d->m_connection
in its destructor (indirectly called by ~QObject) sends DISCONNECT
Control packet and then closes connection, causing
transportConnectionClosed() to call m_clientPrivate->setStateAndError(),
which, in its turn, accesses [a partially destroyed] QMqttClient instance

Change-Id: I216f700d92838dc25e385fe2d449f3ad93a642e6
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
Konstantin Ritt 2020-02-27 05:23:39 +03:00
parent 5ff2e91d95
commit c63c552d2b
2 changed files with 10 additions and 0 deletions

View File

@ -346,6 +346,15 @@ QMqttClient::QMqttClient(QObject *parent) : QObject(*(new QMqttClientPrivate(thi
d->m_connection.setClientPrivate(d);
}
/*!
Deletes a MQTT client. If the MQTT client was not already disconnected from the MQTT broker,
it will be disconnected from automatically.
*/
QMqttClient::~QMqttClient()
{
disconnectFromHost();
}
/*!
Sets the transport to \a device. A transport can be either a socket type
or derived from QIODevice and is specified by \a transport.

View File

@ -111,6 +111,7 @@ private:
Q_PROPERTY(bool autoKeepAlive READ autoKeepAlive WRITE setAutoKeepAlive NOTIFY autoKeepAliveChanged)
public:
explicit QMqttClient(QObject *parent = nullptr);
~QMqttClient() override;
void setTransport(QIODevice *device, TransportType transport);
QIODevice *transport() const;