diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h --- a/compiler-rt/lib/scudo/standalone/primary64.h +++ b/compiler-rt/lib/scudo/standalone/primary64.h @@ -224,9 +224,22 @@ B == nullptr; if (UNLIKELY(!NeedToRefill)) { if (UNLIKELY(B)) { + // Even we always push the number of blocks which is multiple of + // size of `TransferBatch`, the last `TransferBatch` may still + // have less element than size of `TransferBatch` because we + // always fill up the last `TransferBatch` first. When this + // happens, simply push the block in `TransferBatch` and from + // `Array` together. + if (UNLIKELY(B->getCount() == 1)) { + DCHECK_EQ(Size, 1U); + B->appendFromArray(Array, 1U); + Size = 0; + } pushBlocksImpl(C, SizeClassMap::BatchClassId, Region, B->getRawArray(), B->getCount()); CHECK(!Region->FreeListInfo.BlockList.empty()); + if (Size == 0) + return; } pushBlocksImpl(C, SizeClassMap::BatchClassId, Region, Array, Size); return;