From 681e53830675b23cc79e05a386f650039d551bd9 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 12 Apr 2019 18:09:51 +0200 Subject: [PATCH] Fix a crash when a client connects and disconnects without sending any data. The guard for forcing the client to send data within 10 seconds after connecting hadn't been stopped again if the client disconnects on it's own. --- libnymea-mqtt/mqttserver.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libnymea-mqtt/mqttserver.cpp b/libnymea-mqtt/mqttserver.cpp index 96b86c5..b0a37cb 100644 --- a/libnymea-mqtt/mqttserver.cpp +++ b/libnymea-mqtt/mqttserver.cpp @@ -173,7 +173,7 @@ void MqttServerPrivate::onClientConnected(QSslSocket *client) // Start a 10 second timer to clean up the connection if we don't get data until then. QTimer *timeoutTimer = new QTimer(this); - connect(timeoutTimer, &QTimer::timeout, this, [this, client]() { + connect(timeoutTimer, &QTimer::timeout, client, [this, client]() { qCWarning(dbgServer) << "A client connected but did not send data in 10 seconds. Dropping connection."; client->abort(); pendingConnections.take(client)->deleteLater(); @@ -228,6 +228,9 @@ void MqttServerPrivate::cleanupClient(QTcpSocket *client) if (clientServerMap.contains(client)) { clientServerMap.remove(client); } + if (pendingConnections.contains(client)) { + delete pendingConnections.take(client); + } if (clientList.contains(client)) { ClientContext *ctx = clientList.value(client); qCDebug(dbgServer) << "Client" << ctx->clientId << "disconnected.";