diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h index a9a7c2c8ea8618..51721fab52cedf 100644 --- a/compiler-rt/lib/scudo/standalone/secondary.h +++ b/compiler-rt/lib/scudo/standalone/secondary.h @@ -823,7 +823,11 @@ void MapAllocator::deallocate(const Options &Options, void *Ptr) Cache.store(Options, H->CommitBase, H->CommitSize, reinterpret_cast(H + 1), H->MemMap); } else { - unmap(H->MemMap); + // Note that the `H->MemMap` is stored on the pages managed by itself. Take + // over the ownership before unmap() so that any operation along with + // unmap() won't touch inaccessible pages. + MemMapT MemMap = H->MemMap; + unmap(MemMap); } }