From 1f3bc2c4d3fc3bd1a06ab4b3b0148d513d0dd168 Mon Sep 17 00:00:00 2001 From: John Tramm Date: Tue, 14 Jan 2020 01:32:45 +0000 Subject: [PATCH] In some unit tests, OpenMC finalize is called twice in a row without re-initializing the whole simulation. This caused the shared fission bank to be freed twice. Fixed now to check if it is a null pointer, and only free if null. Also initializes this value to null and sets it to null after freeing. --- src/bank.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bank.cpp b/src/bank.cpp index 3bff63d30..27766b5fe 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -19,7 +19,7 @@ namespace simulation { std::vector source_bank; std::vector fission_bank; -Particle::Bank* shared_fission_bank; +Particle::Bank* shared_fission_bank {nullptr}; int shared_fission_bank_length {0}; int shared_fission_bank_max; @@ -33,7 +33,9 @@ void free_memory_bank() { simulation::source_bank.clear(); simulation::fission_bank.clear(); - delete[] simulation::shared_fission_bank; + if( simulation::shared_fission_bank != nullptr ) + delete[] simulation::shared_fission_bank; + simulation::shared_fission_bank = nullptr; simulation::shared_fission_bank_length = 0; }