Index: lib/sanitizer_common/sanitizer_allocator_combined.h =================================================================== --- lib/sanitizer_common/sanitizer_allocator_combined.h +++ lib/sanitizer_common/sanitizer_allocator_combined.h @@ -49,18 +49,19 @@ size = 1; if (size + alignment < size) return ReturnNullOrDieOnBadRequest(); if (check_rss_limit && RssLimitIsExceeded()) return ReturnNullOrDieOnOOM(); + uptr rounded_size = size; if (alignment > 8) - size = RoundUpTo(size, alignment); + rounded_size = RoundUpTo(rounded_size, alignment); void *res; - bool from_primary = primary_.CanAllocate(size, alignment); + bool from_primary = primary_.CanAllocate(rounded_size, alignment); if (from_primary) - res = cache->Allocate(&primary_, primary_.ClassID(size)); + res = cache->Allocate(&primary_, primary_.ClassID(rounded_size)); else res = secondary_.Allocate(&stats_, size, alignment); if (alignment > 8) CHECK_EQ(reinterpret_cast(res) & (alignment - 1), 0); if (cleared && res && from_primary) - internal_bzero_aligned16(res, RoundUpTo(size, 16)); + internal_bzero_aligned16(res, RoundUpTo(rounded_size, 16)); return res; } Index: lib/scudo/scudo_allocator_secondary.h =================================================================== --- lib/scudo/scudo_allocator_secondary.h +++ lib/scudo/scudo_allocator_secondary.h @@ -46,7 +46,7 @@ uptr UserBeg = MapBeg + PageSize + HeadersSize; // In the event of larger alignments, we will attempt to fit the mmap area // better and unmap extraneous memory. This will also ensure that the - // offset field of the header stays small (it will always be 0). + // offset and unused bytes field of the header stay small. if (Alignment > MinAlignment) { if (UserBeg & (Alignment - 1)) UserBeg += Alignment - (UserBeg & (Alignment - 1)); @@ -54,8 +54,9 @@ uptr NewMapBeg = UserBeg - HeadersSize; NewMapBeg = RoundDownTo(NewMapBeg, PageSize) - PageSize; CHECK_GE(NewMapBeg, MapBeg); - uptr NewMapSize = RoundUpTo(MapSize - Alignment, PageSize); - uptr NewMapEnd = NewMapBeg + NewMapSize; + uptr NewMapEnd = + RoundUpTo(UserBeg + Size - Alignment - AlignedChunkHeaderSize, + PageSize) + PageSize; CHECK_LE(NewMapEnd, MapEnd); // Unmap the extra memory if it's large enough. uptr Diff = NewMapBeg - MapBeg; @@ -65,8 +66,8 @@ if (Diff > PageSize) UnmapOrDie(reinterpret_cast(NewMapEnd), Diff); MapBeg = NewMapBeg; - MapSize = NewMapSize; MapEnd = NewMapEnd; + MapSize = NewMapEnd - NewMapBeg; } uptr UserEnd = UserBeg - AlignedChunkHeaderSize + Size; // For larger alignments, Alignment was added by the frontend to Size. Index: lib/scudo/scudo_utils.cpp =================================================================== --- lib/scudo/scudo_utils.cpp +++ lib/scudo/scudo_utils.cpp @@ -17,7 +17,9 @@ #include #include #include -#include +#if defined(__x86_64__) || defined(__i386__) +# include +#endif #include