[compiler-rt] c266bfe - [scudo] Fix missing pushing 1 block to BatchClassId

Chia-hung Duan via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 26 17:04:58 PDT 2023


Author: Chia-hung Duan
Date: 2023-04-27T00:03:39Z
New Revision: c266bfe278bb586ddb03111c6656d5fe3a2ad554

URL: https://github.com/llvm/llvm-project/commit/c266bfe278bb586ddb03111c6656d5fe3a2ad554
DIFF: https://github.com/llvm/llvm-project/commit/c266bfe278bb586ddb03111c6656d5fe3a2ad554.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 4ea1ba367764f..b954b7c0bf2ae 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -201,16 +201,18 @@ template <typename Config> class SizeClassAllocator64 {
         // 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 @@ template <typename Config> class SizeClassAllocator64 {
         // when it happens.
         reportOutOfBatchClass();
       }
+
       return;
     }
 


        


More information about the llvm-commits mailing list