summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qcontiguouscache.h
diff options
context:
space:
mode:
authorFabian Bumberger <fbumberger@rim.com>2012-08-27 17:29:18 -0400
committerQt by Nokia <qt-info@nokia.com>2012-08-30 02:29:00 +0200
commitb4075c8ea31b235cdbb61fcd6290105b9914d627 (patch)
treea14ff7697c38500e46bf41725b2f6347fa29977b /src/corelib/tools/qcontiguouscache.h
parentc2f10f915fd6fa4d38c83a4c8b0e1c63a254643a (diff)
Fixes possible memory leak in QContiguousCache
When inserting an item on a position that is already occupied, the destructor of the old item was never invoked. Change-Id: I01dc4ec9f2da5027284eba94e1a9ad36b062a50d Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qcontiguouscache.h')
-rw-r--r--src/corelib/tools/qcontiguouscache.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 248a8e580e..469160bff2 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -387,10 +387,12 @@ void QContiguousCache<T>::insert(int pos, const T &value)
Q_ASSERT_X(pos >= 0 && pos < INT_MAX, "QContiguousCache<T>::insert", "index out of range");
detach();
if (containsIndex(pos)) {
- if(QTypeInfo<T>::isComplex)
+ if (QTypeInfo<T>::isComplex) {
+ (p->array + pos % d->alloc)->~T();
new (p->array + pos % d->alloc) T(value);
- else
+ } else {
p->array[pos % d->alloc] = value;
+ }
} else if (pos == d->offset-1)
prepend(value);
else if (pos == d->offset+d->count)