From 301f7b780cbb0e5b1f6c9bf88bdb7dffe9b1110e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 10 Nov 2011 18:13:36 +0100 Subject: Don't check reference count in QLinkedList::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 Reviewed-by: Olivier Goffart Reviewed-by: Bradley T. Hughes --- src/corelib/tools/qlinkedlist.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/corelib/tools/qlinkedlist.h') diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index 966b74ddfa..279eda673a 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -266,6 +266,7 @@ void QLinkedList::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::free(QLinkedListData *x) { Node *y = reinterpret_cast(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 -- cgit v1.2.3