[libcxx-commits] [libcxx] [libc++] Fix "leak" of PMR resource in benchmark (PR #216114)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Aug 13 09:47:21 PDT 2026


================
@@ -147,18 +147,21 @@ void associative_container_benchmarks(std::string container) {
     std::pmr::monotonic_buffer_resource rs2(size * 64 * BatchSize); // 64 bytes should be enough per node
     while (st.KeepRunningBatch(BatchSize)) {
       for (std::size_t i = 0; i != BatchSize; ++i) {
-        new (c + i * sizeof(PMRContainer)) PMRContainer(std::move(srcs[i]), &rs2);
-        benchmark::DoNotOptimize(c + i);
+        PMRContainer* p = reinterpret_cast<PMRContainer*>(c) + i;
+        new (p) PMRContainer(std::move(srcs[i]), &rs2);
+        benchmark::DoNotOptimize(p);
         benchmark::ClobberMemory();
       }
 
       st.PauseTiming();
       for (std::size_t i = 0; i != BatchSize; ++i) {
-        reinterpret_cast<PMRContainer*>(c + i * sizeof(PMRContainer))->~PMRContainer();
+        PMRContainer* p = reinterpret_cast<PMRContainer*>(c) + i;
+        p->~PMRContainer();
       }
       rs2.release();
       srcs.clear();
-      for (size_t i = 0; i != BatchSize; ++i)
+      rs.release();
----------------
ldionne wrote:

This is the main fix. This isn't a leak per se, but we'd unboundedly allocate inside `rs` without ever releasing it.

https://github.com/llvm/llvm-project/pull/216114


More information about the libcxx-commits mailing list