[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

GitOrigin-RevId: c266bfe278bb586ddb03111c6656d5fe3a2ad554
diff --git a/primary64.h b/primary64.h
index 4ea1ba3..b954b7c 100644
--- a/primary64.h
+++ b/primary64.h
@@ -201,16 +201,18 @@
         // 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 @@
         // when it happens.
         reportOutOfBatchClass();
       }
+
       return;
     }