diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp index 4a3fd73dc1f..6ca739c3059 100644 --- a/src/corelib/tools/qcontiguouscache.cpp +++ b/src/corelib/tools/qcontiguouscache.cpp @@ -22,7 +22,8 @@ void QContiguousCacheData::dump() const QContiguousCacheData *QContiguousCacheData::allocateData(qsizetype size, qsizetype alignment) { - return static_cast(qMallocAligned(size_t(size), size_t(alignment))); + void *mem = qMallocAligned(size_t(size), size_t(alignment)); + return new (mem) QContiguousCacheData{/*ref=*/1, 0, 0, 0, 0}; } void QContiguousCacheData::freeData(QContiguousCacheData *data) diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index e630b56cfa1..8dfa0874050 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -152,7 +152,6 @@ template void QContiguousCache::detach_helper() { Data *x = allocateData(d->alloc); - x->ref.storeRelaxed(1); x->count = d->count; x->start = d->start; x->offset = d->offset; @@ -184,7 +183,6 @@ void QContiguousCache::setCapacity(qsizetype asize) return; detach(); Data *x = allocateData(asize); - x->ref.storeRelaxed(1); x->alloc = asize; x->count = qMin(d->count, asize); x->offset = d->offset + d->count - x->count; @@ -231,7 +229,6 @@ void QContiguousCache::clear() d->count = d->start = d->offset = 0; } else { Data *x = allocateData(d->alloc); - x->ref.storeRelaxed(1); x->alloc = d->alloc; x->count = x->start = x->offset = 0; if (!d->ref.deref()) @@ -251,7 +248,6 @@ QContiguousCache::QContiguousCache(qsizetype cap) { Q_ASSERT(cap >= 0); d = allocateData(cap); - d->ref.storeRelaxed(1); d->alloc = cap; d->count = d->start = d->offset = 0; }