Prevent accidental double-frees

- matcher.cpp, survey.cpp: setting the state pointer to null/nullptr in ::shutdown() to prevent errors caused by accidental double-frees - an additional check if the pointer is null already is not necessary as the standard guarantees that nothing happens if delete is called on a nullpointer

Co-Authored-By: Alan <3719547+lethosor@users.noreply.github.com>
develop
bseiller 2021-02-20 22:43:12 +01:00
parent efe62b412c
commit 60e83046f8
2 changed files with 4 additions and 2 deletions

@ -68,7 +68,7 @@ namespace embark_assist {
embark_assist::defs::mid_level_tiles mlt; embark_assist::defs::mid_level_tiles mlt;
}; };
static states *state; static states *state = nullptr;
//======================================================================================= //=======================================================================================
@ -2731,6 +2731,7 @@ void embark_assist::matcher::setup() {
void embark_assist::matcher::shutdown() { void embark_assist::matcher::shutdown() {
delete state; delete state;
state = nullptr;
} }
//======================================================================================= //=======================================================================================

@ -75,7 +75,7 @@ namespace embark_assist {
uint16_t max_inorganic; uint16_t max_inorganic;
}; };
static states *state; static states *state = nullptr;
//======================================================================================= //=======================================================================================
@ -2548,5 +2548,6 @@ void embark_assist::survey::survey_embark(embark_assist::defs::mid_level_tiles *
void embark_assist::survey::shutdown() { void embark_assist::survey::shutdown() {
delete state; delete state;
state = nullptr;
} }