Skip to content

Commit

Permalink
[Scudo] Fix SizeClassAllocatorLocalCache::drain
Browse files Browse the repository at this point in the history
It leaved few blocks in PerClassArray[0].

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D99763
  • Loading branch information
vitalybuka committed Apr 1, 2021
1 parent da98177 commit ce9e1a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion compiler-rt/lib/scudo/standalone/local_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,22 @@ template <class SizeClassAllocator> struct SizeClassAllocatorLocalCache {
Stats.add(StatFree, ClassSize);
}

bool isEmpty() const {
for (uptr I = 0; I < NumClasses; ++I)
if (PerClassArray[I].Count)
return false;
return true;
}

void drain() {
for (uptr I = 0; I < NumClasses; I++) {
// Drain BatchClassId (0) the last as createBatch can refill it.
for (uptr I = NumClasses; I;) {
--I;
PerClass *C = &PerClassArray[I];
while (C->Count > 0)
drain(C, I);
}
DCHECK(isEmpty());
}

TransferBatch *createBatch(uptr ClassId, void *B) {
Expand Down
8 changes: 8 additions & 0 deletions compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ template <class Config> static void testAllocator() {
EXPECT_NE(Stats.find("Stats: SizeClassAllocator"), std::string::npos);
EXPECT_NE(Stats.find("Stats: MapAllocator"), std::string::npos);
EXPECT_NE(Stats.find("Stats: Quarantine"), std::string::npos);

bool UnlockRequired;
auto *TSD = Allocator->getTSDRegistry()->getTSDAndLock(&UnlockRequired);
EXPECT_TRUE(!TSD->Cache.isEmpty());
TSD->Cache.drain();
EXPECT_TRUE(TSD->Cache.isEmpty());
if (UnlockRequired)
TSD->unlock();
}

// Test that multiple instantiations of the allocator have not messed up the
Expand Down

0 comments on commit ce9e1a3

Please sign in to comment.