diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2011-11-10 18:13:36 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-17 10:17:01 +0100 |
commit | 301f7b780cbb0e5b1f6c9bf88bdb7dffe9b1110e (patch) | |
tree | 67392c05fccecdeaee6b432c6cf670361982462c /src | |
parent | b3a4d3e328a3d80d4728716f2e5e68817b82cbb8 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qlinkedlist.h | 14 |
1 files changed, 7 insertions, 7 deletions
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<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> |