summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2012-03-14 09:46:02 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-19 11:53:07 +0100
commit25cf5dabbe0c1a4321e414d6fd1859f614442747 (patch)
tree3847142e44a83db0da1ca3eaa573b4f423330edd
parentfb4c976a0e0b5c6b8dfb7d7c35fe8e6772d4a876 (diff)
Fix a memory leak in template QMetaObject::Connection.
QObject::QSlotObjectBase instance given as argument to QObject::connectImpl was not dereferenced in case of an unsuccessful connection. Change-Id: I206b14e986690c027aafc2593762d85dc619e0e6 Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
-rw-r--r--src/corelib/kernel/qobject.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index b648432e11..25adee7cc7 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -3991,6 +3991,8 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
{
if (!sender || !signal || !slotObj || !senderMetaObject) {
qWarning("QObject::connect: invalid null parametter");
+ if (slotObj && !slotObj->ref.deref())
+ delete slotObj;
return QMetaObject::Connection();
}
int signal_index = -1;
@@ -3998,6 +4000,8 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
senderMetaObject->static_metacall(QMetaObject::IndexOfMethod, 0, args);
if (signal_index < 0 || signal_index >= QMetaObjectPrivate::get(senderMetaObject)->signalCount) {
qWarning("QObject::connect: signal not found in %s", senderMetaObject->className());
+ if (!slotObj->ref.deref())
+ delete slotObj;
return QMetaObject::Connection(0);
}
int signalOffset, methodOffset;
@@ -4017,8 +4021,11 @@ QMetaObject::Connection QObject::connectImpl(const QObject *sender, void **signa
(*connectionLists)[signal_index].first;
while (c2) {
- if (c2->receiver == receiver && c2->isSlotObject && c2->slotObj->compare(slot))
+ if (c2->receiver == receiver && c2->isSlotObject && c2->slotObj->compare(slot)) {
+ if (!slotObj->ref.deref())
+ delete slotObj;
return QMetaObject::Connection();
+ }
c2 = c2->nextConnectionList;
}
}