The passed in space_size had left_padding added to it.
This is wrong because in the implementation FindAvailableMemoryRange
the computed size of the found region has the left_padding subtracted
(possibly more due to alignment) already.
Here's the relevant snippet from FindAvailableMemoryRange.
// We found a free region [free_begin..address-1]. uptr gap_start = RoundUpTo((uptr)free_begin + left_padding, alignment); uptr gap_end = RoundDownTo((uptr)address, alignment); uptr gap_size = gap_end > gap_start ? gap_end - gap_start : 0; if (size < gap_size) { return gap_start; }
In the size comparison (size < gap_size) gap_size doesn't
include padding so size shouldn't either.
rdar://problem/66603866