QMetaObject::invokeMethod: don't leak the slot object

QMetaCallEvent references up, so we need to drop by one. In all other
cases, we need to drop the reference to zero and delete.

[ChangeLog][QtCore][QMetaObject] Fixed a memory leak that happened when
the new-style call to invokeMethod() was used.

Task-number: QTBUG-65462
Change-Id: I39332e0a867442d58082fffd15034b99e31c92a1
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
bb10
Thiago Macieira 2017-12-24 15:37:04 -02:00 committed by Olivier Goffart (Woboq GmbH)
parent ec76525254
commit 57318ce8c2
1 changed files with 6 additions and 0 deletions

View File

@ -1491,6 +1491,12 @@ bool QMetaObject::invokeMethod(QObject *obj,
bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slot, Qt::ConnectionType type, void *ret)
{
struct Holder {
QtPrivate::QSlotObjectBase *obj;
~Holder() { obj->destroyIfLastRef(); }
} holder = { slot };
Q_UNUSED(holder);
if (! object)
return false;