Bug 1402283 - Make arena_ralloc use the same arena as the original pointer when none is provided. r=njn
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 09 Nov 2017 09:51:10 +0900
changeset 444399 3f44c449e280d5b1327028ccfdc0505070336209
parent 444398 e2df7f0bf18245e0644b170a7b0173928da76afc
child 444400 6e0e82c6b316d742c9f92d96aa59198caa418499
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1402283
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
memory/build/mozjemalloc.cpp
--- 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