[scudo] Skip releaseToOSMaybe if there's no byte in freelist
authorChia-hung Duan <chiahungduan@google.com>
Wed, 10 May 2023 02:40:48 +0000 (02:40 +0000)
committerChia-hung Duan <chiahungduan@google.com>
Wed, 10 May 2023 20:20:17 +0000 (20:20 +0000)
In primary32, the unused region will have max/min region index with 0
value and it's an invalid index. Skip releaseToOSMaybe in both primary32
and primary64 even it's M_PURGE_ALL.

Differential Revision: https://reviews.llvm.org/D150243

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

index 7ac8df9..726db75 100644 (file)
@@ -737,6 +737,9 @@ private:
         Sci->AllocatedUser -
         (Sci->Stats.PoppedBlocks - Sci->Stats.PushedBlocks) * BlockSize;
 
+    if (UNLIKELY(BytesInFreeList == 0))
+      return 0;
+
     bool MaySkip = false;
 
     if (BytesInFreeList <= Sci->ReleaseInfo.BytesInFreeListAtLastCheckpoint) {
index b954b7c..3924837 100644 (file)
@@ -845,6 +845,9 @@ private:
         Region->AllocatedUser -
         (Region->Stats.PoppedBlocks - Region->Stats.PushedBlocks) * BlockSize;
 
+    if (UNLIKELY(BytesInFreeList == 0))
+      return 0;
+
     bool MaySkip = false;
 
     // Always update `BytesInFreeListAtLastCheckpoint` with the smallest value