Bug 1067018 - Make sure calloc/malloc/free usages match in Tools.h; r=jwatt

This commit is contained in:
Jim Chen 2014-09-25 13:08:23 -04:00
parent abf0ba5dbd
commit d43388fc2f

View File

@ -133,14 +133,14 @@ struct AlignedArray
}
#endif
delete [] mStorage;
moz_free(mStorage);
mStorage = nullptr;
mPtr = nullptr;
}
MOZ_ALWAYS_INLINE void Realloc(size_t aCount, bool aZero = false)
{
delete [] mStorage;
moz_free(mStorage);
CheckedInt32 storageByteCount =
CheckedInt32(sizeof(T)) * aCount + (alignment - 1);
if (!storageByteCount.isValid()) {
@ -152,9 +152,11 @@ struct AlignedArray
// We don't create an array of T here, since we don't want ctors to be
// invoked at the wrong places if we realign below.
if (aZero) {
mStorage = static_cast<uint8_t *>(calloc(1, storageByteCount.value()));
// calloc can be more efficient than new[] for large chunks,
// so we use calloc/malloc/free for everything.
mStorage = static_cast<uint8_t *>(moz_calloc(1, storageByteCount.value()));
} else {
mStorage = new (std::nothrow) uint8_t[storageByteCount.value()];
mStorage = static_cast<uint8_t *>(moz_malloc(storageByteCount.value()));
}
if (!mStorage) {
mStorage = nullptr;