[scudo] Don't unmap other low memory pages if mapping doesn't exist
authorDominic Chen <ddchen@apple.com>
Wed, 16 Mar 2022 20:51:08 +0000 (13:51 -0700)
committerDominic Chen <ddchen@apple.com>
Thu, 17 Mar 2022 17:17:36 +0000 (10:17 -0700)
Tests can register multiple allocators, but only the first will initialize since it initializes the TSDRegistrySharedT. Then, destruction of subsequent allocator may end up unmapping a nullptr PrimaryBase with non-zero PrimarySize.

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

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

index 6c17855..14784ee 100644 (file)
@@ -89,7 +89,9 @@ public:
       RegionInfo *Region = getRegionInfo(I);
       *Region = {};
     }
-    unmap(reinterpret_cast<void *>(PrimaryBase), PrimarySize, UNMAP_ALL, &Data);
+    if (PrimaryBase)
+      unmap(reinterpret_cast<void *>(PrimaryBase), PrimarySize, UNMAP_ALL,
+            &Data);
     PrimaryBase = 0U;
   }