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 <marc.mutz@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 061ab84e98a3457c361287084e0c1e9a396ab197)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Mårten Nordheim 2023-07-18 09:14:05 +02:00 committed by Qt Cherry-pick Bot
parent 46af7d3d1f
commit 2adc225391
2 changed files with 8 additions and 1 deletions

View File

@ -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;

View File

@ -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);