From e6c646a67858f98a255e80994e5920e932298164 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 4 Jul 2019 15:39:36 +0200 Subject: QHostInfoRunnable: make the lookupFinished() call more robust Use a scope guard to reliably mark the runnable as finished with the manager, lest a deleted runnable lingers in the manager's currentLookups for too long/ever. Change-Id: I89eff49931d0428f4e75789a0a1188edb1f66220 Reviewed-by: Volker Hilsheimer --- src/network/kernel/qhostinfo.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/network/kernel/qhostinfo.cpp') diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 6302ad62eb..6caee5e097 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -826,11 +827,10 @@ QHostInfoRunnable::QHostInfoRunnable(const QString &hn, int i, const QObject *re void QHostInfoRunnable::run() { QHostInfoLookupManager *manager = theHostInfoLookupManager(); + const auto sg = qScopeGuard([&] { manager->lookupFinished(this); }); // check aborted - if (manager->wasAborted(id)) { - manager->lookupFinished(this); + if (manager->wasAborted(id)) return; - } QHostInfo hostInfo; @@ -852,10 +852,8 @@ void QHostInfoRunnable::run() } // check aborted again - if (manager->wasAborted(id)) { - manager->lookupFinished(this); + if (manager->wasAborted(id)) return; - } // signal emission hostInfo.setLookupId(id); @@ -879,8 +877,6 @@ void QHostInfoRunnable::run() } #endif - manager->lookupFinished(this); - // thread goes back to QThreadPool } -- cgit v1.2.3