Skip to content

Commit c266bfe

Browse files
committed
[scudo] Fix missing pushing 1 block to BatchClassId
This was happened rarely. The only case is when a thread is teared down and it only has one block of BatchClass and the freelist of BatchClass is empty. The impact is leaking 1 block of BatchClass and which is minor. Differential Revision: https://reviews.llvm.org/D149141
1 parent 15ca900 commit c266bfe

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

compiler-rt/lib/scudo/standalone/primary64.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,18 @@ template <typename Config> class SizeClassAllocator64 {
201201
// cause a recursive allocation). However, The number of free blocks may
202202
// be less than two. Therefore, populate the free list before inserting
203203
// the blocks.
204-
if (Size >= 2U) {
204+
const bool NeedToRefill = Size == 1U && Region->FreeList.empty();
205+
// If BatchClass has been exhausted, the program should have been
206+
// aborted.
207+
DCHECK(!Region->Exhausted);
208+
209+
if (UNLIKELY(
210+
NeedToRefill &&
211+
!populateFreeList(C, SizeClassMap::BatchClassId, Region))) {
212+
PrintStats = true;
213+
} else {
205214
pushBlocksImpl(C, SizeClassMap::BatchClassId, Region, Array, Size);
206215
Region->Stats.PushedBlocks += Size;
207-
} else {
208-
const bool RegionIsExhausted = Region->Exhausted;
209-
if (UNLIKELY(
210-
RegionIsExhausted ||
211-
!populateFreeList(C, SizeClassMap::BatchClassId, Region))) {
212-
PrintStats = !RegionIsExhausted && Region->Exhausted;
213-
}
214216
}
215217
}
216218

@@ -227,6 +229,7 @@ template <typename Config> class SizeClassAllocator64 {
227229
// when it happens.
228230
reportOutOfBatchClass();
229231
}
232+
230233
return;
231234
}
232235

0 commit comments

Comments
 (0)