diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2023-07-18 09:14:05 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2023-07-19 14:16:55 +0200 |
commit | 061ab84e98a3457c361287084e0c1e9a396ab197 (patch) | |
tree | 0ec99420992cf64c6b32a2d91ff2538251c10049 | |
parent | 1e3bf107864f0fdaf671464c53eb94a5e3f9c561 (diff) |
QHostInfo: fix leaking slot object
We were not ref'ing or deref'ing the slot object in the various places
that owned it. So, if, in the end, the QHostInfoResult object didn't
call the slot we would leak the slot object.
Pick-to: 6.6 6.5 6.2 5.15
Fixes: QTBUG-115263
Change-Id: I45f43756c7589470045d97b59257ccfd85a325b7
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 1 | ||||
-rw-r--r-- | src/network/kernel/qhostinfo_p.h | 8 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index ea2ffedd4c..5cb8cf6bed 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -124,7 +124,6 @@ bool QHostInfoResult::event(QEvent *event) // we didn't have a context object, or it's still alive if (!withContextObject || receiver) slotObj->call(const_cast<QObject*>(receiver.data()), args); - slotObj->destroyIfLastRef(); deleteLater(); return true; diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 2176b464ae..28654f4e14 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -51,6 +51,12 @@ public: moveToThread(receiver->thread()); } + ~QHostInfoResult() + { + if (slotObj) + slotObj->destroyIfLastRef(); + } + void postResultsReady(const QHostInfo &info); Q_SIGNALS: @@ -64,6 +70,8 @@ private: : receiver(other->receiver), slotObj(other->slotObj), withContextObject(other->withContextObject) { + if (slotObj) + slotObj->ref(); // cleanup if the application terminates before results are delivered connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &QObject::deleteLater); |