From 2adc2253911983c58a29f4e1ba144c0fe1677b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 18 Jul 2023 09:14:05 +0200 Subject: [PATCH] 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. Fixes: QTBUG-115263 Change-Id: I45f43756c7589470045d97b59257ccfd85a325b7 Reviewed-by: Marc Mutz Reviewed-by: Volker Hilsheimer (cherry picked from commit 061ab84e98a3457c361287084e0c1e9a396ab197) Reviewed-by: Qt Cherry-pick Bot --- src/network/kernel/qhostinfo.cpp | 1 - src/network/kernel/qhostinfo_p.h | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index ea2ffedd4cb..5cb8cf6bed8 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(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 2176b464aed..28654f4e141 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);