From 4b9ead80665b1da85bb4ef620232cb2cfc8b0c80 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Mon, 12 Jul 2021 19:50:36 +0100 Subject: [PATCH] Fix register_clean_up being called with ScopedAllocator. (#344) --- src/mem/scopedalloc.h | 5 ++++- .../thread_alloc_external/thread_alloc_external.cc | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mem/scopedalloc.h b/src/mem/scopedalloc.h index d0e179e..345635a 100644 --- a/src/mem/scopedalloc.h +++ b/src/mem/scopedalloc.h @@ -25,7 +25,10 @@ namespace snmalloc /** * Constructor. Claims an allocator from the global pool */ - ScopedAllocator() = default; + ScopedAllocator() + { + alloc.init(); + }; /** * Copying is not supported, it could easily lead to accidental sharing of diff --git a/src/test/func/thread_alloc_external/thread_alloc_external.cc b/src/test/func/thread_alloc_external/thread_alloc_external.cc index 7403824..16fed06 100644 --- a/src/test/func/thread_alloc_external/thread_alloc_external.cc +++ b/src/test/func/thread_alloc_external/thread_alloc_external.cc @@ -37,4 +37,15 @@ int main() } ThreadAlloc::get().teardown(); + + // This checks that the scoped allocator does not call + // register clean up, as this configuration will fault + // if that occurs. + auto a2 = ScopedAllocator(); + for (size_t i = 0; i < 1000; i++) + { + auto r1 = a2->alloc(i); + + a2->dealloc(r1); + } }