Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.5.3
-
None
Description
Scenario: subscribing an MQTT topic for a certain duration, using QMqttSubscription's destructor instead of its unsubscribe() method.
The bug: the QMqttConnection class keeps references to the destroyed object beyond its lifetime, leading to a segfault.
Here's a simple way to reproduce (it needs an active broker running on localhost):
#include "qmqttclient.h" int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); auto *client = new QMqttClient(&app); client->setHostname("localhost"); client->setPort(1883); client->setClientId(QCoreApplication::applicationName()); client->connectToHost(); QObject::connect(client, &QMqttClient::connected, client, [client] { auto *sub = client->subscribe({ "temporaryinterest" }, 0); QTimer::singleShot(100, [sub]() { delete sub; }); }); return app.exec(); }