diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-07-04 15:39:36 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-07-09 07:09:51 +0200 |
commit | e6c646a67858f98a255e80994e5920e932298164 (patch) | |
tree | 7ebfaae848b603e7ac99d859e2112c2cadd74c76 /src/network | |
parent | 60ca2f5f7c38178cfe62d3dbe1b8dacfe43cbac9 (diff) |
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 <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
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 <qabstracteventdispatcher.h> #include <qcoreapplication.h> #include <qmetaobject.h> +#include <qscopeguard.h> #include <qstringlist.h> #include <qthread.h> #include <qurl.h> @@ -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 } |