Ping: Clean up replies properly if they get deleted before finished
This commit is contained in:
parent
da6d7b8efe
commit
6a08de4763
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user