Don't check reference count in QLinkedList<T>::free

This is a private function that was always* called after d->ref.deref()
returned false to free the linked list. Still, it needlessly verified
the reference count to be zero.

The check is thus replaced with a Q_ASSERT to check the invariant on
debug builds.

*This commit also fixes an issue where free would be called on a block
that hadn't been deref'ed, thus leaking the nodes. Since this was in an
exception handling block, and happens before any code has a chance to
reference the block the explicit deref is skipped in that case.

Change-Id: Ie73c174d0a1b84f297bf5531e45f829e66a46346
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
João Abecasis 2011-11-10 18:13:36 +01:00 committed by Qt by Nokia
parent b3a4d3e328
commit 301f7b780c

View File

@ -266,6 +266,7 @@ void QLinkedList<T>::detach_helper()
copy = copy->n;
} QT_CATCH(...) {
copy->n = x.e;
Q_ASSERT(!x.d->ref.deref()); // Don't trigger assert in free
free(x.d);
QT_RETHROW;
}
@ -282,14 +283,13 @@ void QLinkedList<T>::free(QLinkedListData *x)
{
Node *y = reinterpret_cast<Node*>(x);
Node *i = y->n;
if (x->ref == 0) {
while(i != y) {
Node *n = i;
i = i->n;
delete n;
}
delete x;
Q_ASSERT(x->ref.atomic.load() == 0);
while (i != y) {
Node *n = i;
i = i->n;
delete n;
}
delete x;
}
template <typename T>