summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChia-hung Duan <chiahungduan@google.com>2023-04-25 07:32:57 +0000
committerChia-hung Duan <chiahungduan@google.com>2023-04-28 01:23:32 +0000
commit23cb39cc900955ed2309a94894e5b321b86b5363 (patch)
tree33861cfb1c9031f72536c214ad79f5401773dfe1
parent8f637a54c5929491950b7aaf43d6d3c58ff5ca37 (diff)
downloadscudo-23cb39cc900955ed2309a94894e5b321b86b5363.tar.gz
[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 Bug: b/279990828 GitOrigin-RevId: c266bfe278bb586ddb03111c6656d5fe3a2ad554 Change-Id: I62e425ba1fdc6a0575c301eae09ccc7289ce7ac6 Merged-In: I62e425ba1fdc6a0575c301eae09ccc7289ce7ac6 (cherry picked from commit 74fab6bece88074d9e4b007a8bbd5aed199e2037)
-rw-r--r--standalone/primary64.h19
1 files changed, 11 insertions, 8 deletions
diff --git a/standalone/primary64.h b/standalone/primary64.h
index 4ea1ba36776..b954b7c0bf2 100644
--- a/standalone/primary64.h
+++ b/standalone/primary64.h
@@ -201,16 +201,18 @@ public:
// cause a recursive allocation). However, The number of free blocks may
// be less than two. Therefore, populate the free list before inserting
// the blocks.
- if (Size >= 2U) {
+ const bool NeedToRefill = Size == 1U && Region->FreeList.empty();
+ // If BatchClass has been exhausted, the program should have been
+ // aborted.
+ DCHECK(!Region->Exhausted);
+
+ if (UNLIKELY(
+ NeedToRefill &&
+ !populateFreeList(C, SizeClassMap::BatchClassId, Region))) {
+ PrintStats = true;
+ } else {
pushBlocksImpl(C, SizeClassMap::BatchClassId, Region, Array, Size);
Region->Stats.PushedBlocks += Size;
- } else {
- const bool RegionIsExhausted = Region->Exhausted;
- if (UNLIKELY(
- RegionIsExhausted ||
- !populateFreeList(C, SizeClassMap::BatchClassId, Region))) {
- PrintStats = !RegionIsExhausted && Region->Exhausted;
- }
}
}
@@ -227,6 +229,7 @@ public:
// when it happens.
reportOutOfBatchClass();
}
+
return;
}