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>
This commit is contained in:
Jędrzej Nowacki 2012-03-14 09:46:02 +01:00 committed by Qt by Nokia
parent fb4c976a0e
commit 25cf5dabbe

View File

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