diff --git a/libnymea/network/ping.cpp b/libnymea/network/ping.cpp index be53b8e4..54e6dc2d 100644 --- a/libnymea/network/ping.cpp +++ b/libnymea/network/ping.cpp @@ -317,21 +317,13 @@ PingReply *Ping::createReply(const QHostAddress &hostAddress) }); connect(reply, &PingReply::finished, this, [=](){ + cleanUpReply(reply); reply->deleteLater(); + }); - // Cleanup any retry left over queue stuff - if (m_currentReply == reply) - m_currentReply = nullptr; - - m_pendingReplies.remove(reply->requestId()); - m_replyQueue.removeAll(reply); - - if (m_pendingHostLookups.values().contains(reply)) { - // Abort any pending host lookups, the reply has been finished - int lookupId = m_pendingHostLookups.key(reply); - QHostInfo::abortHostLookup(lookupId); - m_pendingHostLookups.remove(lookupId); - } + // Just in case the reply get's deleted before beeing able to finish ... + connect(reply, &PingReply::destroyed, this, [=](){ + cleanUpReply(reply); }); return reply; @@ -373,6 +365,23 @@ void Ping::finishReply(PingReply *reply, PingReply::Error error) } } +void Ping::cleanUpReply(PingReply *reply) +{ + // Cleanup any retry left over queue stuff + if (m_currentReply == reply) + m_currentReply = nullptr; + + m_pendingReplies.remove(reply->requestId()); + m_replyQueue.removeAll(reply); + + if (m_pendingHostLookups.values().contains(reply)) { + // Abort any pending host lookups, the reply has been finished + int lookupId = m_pendingHostLookups.key(reply); + QHostInfo::abortHostLookup(lookupId); + m_pendingHostLookups.remove(lookupId); + } +} + void Ping::onSocketReadyRead(int socketDescriptor) { // We must read all data otherwise the socket notifier does not work as expected diff --git a/libnymea/network/ping.h b/libnymea/network/ping.h index 7da73d6c..3545b196 100644 --- a/libnymea/network/ping.h +++ b/libnymea/network/ping.h @@ -105,6 +105,7 @@ private: PingReply *createReply(const QHostAddress &hostAddress); void finishReply(PingReply *reply, PingReply::Error error); + void cleanUpReply(PingReply *reply); private slots: void onSocketReadyRead(int socketDescriptor);