Bug 1402283 - Make arena_ralloc use the same arena as the original pointer when none is provided. r?njn
When using plain realloc() on a pointer that was allocated with
moz_arena_malloc, we want the resulting pointer to still belong to the
same arena.
--- a/memory/build/mozjemalloc.cpp
+++ b/memory/build/mozjemalloc.cpp
@@ -3713,17 +3713,21 @@ arena_ralloc(void* aPtr, size_t aSize, s
if (arena_ralloc_large(aPtr, aSize, aOldSize)) {
return aPtr;
}
}
// If we get here, then aSize and aOldSize are different enough that we
// need to move the object. In that case, fall back to allocating new
// space and copying.
- aArena = aArena ? aArena : choose_arena(aSize);
+ if (!aArena) {
+ arena_chunk_t* chunk = GetChunkForPtr(aPtr);
+ aArena = chunk->arena;
+ MOZ_DIAGNOSTIC_ASSERT(aArena->mMagic == ARENA_MAGIC);
+ }
ret = aArena->Malloc(aSize, false);
if (!ret) {
return nullptr;
}
// Junk/zero-filling were already done by arena_t::Malloc().
copysize = (aSize < aOldSize) ? aSize : aOldSize;
#ifdef VM_COPY_MIN