diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp @@ -92,10 +92,11 @@ uptr res = map_res; if (!IsAligned(res, alignment)) { res = (map_res + alignment - 1) & ~(alignment - 1); - UnmapOrDie((void*)map_res, res - map_res); + if (IsAligned(map_res, GetPageSizeCached())) + UnmapOrDie((void*)map_res, res - map_res); } uptr end = res + size; - if (end != map_end) + if (end != map_end && IsAligned(end, GetPageSizeCached())) UnmapOrDie((void*)end, map_end - end); return (void*)res; }