From 848b869cdf10fdd6c00ab1ad0d048ae1091cf64a Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 17 Jan 2019 10:21:22 +0100 Subject: [PATCH] SocketAPI: Remove listener immediately on lost connection To avoid situations where messages are attempted to be sent to dead connections. --- src/gui/socketapi.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index ac1aea1a2..a42033211 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -270,6 +270,10 @@ void SocketApi::onLostConnection() { qCInfo(lcSocketApi) << "Lost connection " << sender(); sender()->deleteLater(); + + auto socket = qobject_cast(sender()); + ASSERT(socket); + _listeners.erase(std::remove_if(_listeners.begin(), _listeners.end(), ListenerHasSocketPred(socket)), _listeners.end()); } void SocketApi::slotSocketDestroyed(QObject *obj) -- 2.30.2