File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -253,12 +253,13 @@ Arena::Initialize ()
253253 if (initialized) return ;
254254 initialized = true ;
255255
256- BL_ASSERT (the_arena == nullptr );
256+ // see reason on allowed reuse of the default CPU BArena in Arena::Finalize
257+ BL_ASSERT (the_arena == nullptr || the_arena == The_BArena ());
257258 BL_ASSERT (the_async_arena == nullptr );
258- BL_ASSERT (the_device_arena == nullptr );
259- BL_ASSERT (the_managed_arena == nullptr );
259+ BL_ASSERT (the_device_arena == nullptr || the_device_arena == The_BArena () );
260+ BL_ASSERT (the_managed_arena == nullptr || the_managed_arena == The_BArena () );
260261 BL_ASSERT (the_pinned_arena == nullptr );
261- BL_ASSERT (the_cpu_arena == nullptr );
262+ BL_ASSERT (the_cpu_arena == nullptr || the_cpu_arena == The_BArena () );
262263
263264#ifdef AMREX_USE_GPU
264265#ifdef AMREX_USE_DPCPP
@@ -468,6 +469,13 @@ Arena::Finalize ()
468469
469470 initialized = false ;
470471
472+ // we reset Arenas unless they are the default "CPU malloc/free" BArena
473+ // this is because we want to allow users to free their UB objects
474+ // that they forgot to destruct after amrex::Finalize():
475+ // amrex::Initialize(...);
476+ // MultiFab mf(...); // this should be scoped in { ... }
477+ // amrex::Finalize();
478+ // mf cannot be used now, but it can at least be freed without a segfault
471479 if (!dynamic_cast <BArena*>(the_device_arena)) {
472480 if (the_device_arena != the_arena) {
473481 delete the_device_arena;
You can’t perform that action at this time.
0 commit comments