Skip to content

Commit

Permalink
QMetaObject::invokeMethod: don't leak the slot object
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
thiagomacieira authored and ogoffart committed Jan 14, 2018
1 parent ec76525 commit 57318ce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/corelib/kernel/qmetaobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 57318ce

Please sign in to comment.