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.

This commit is contained in:
John Tramm 2020-01-14 01:32:45 +00:00
parent ad96fa6ffa
commit 1f3bc2c4d3

View file

@ -19,7 +19,7 @@ namespace simulation {
std::vector<Particle::Bank> source_bank;
std::vector<Particle::Bank> 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;
}