Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 60e8304

Browse files
bseillerlethosor
andcommitted
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 <[email protected]>
1 parent efe62b4 commit 60e8304

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

plugins/embark-assistant/matcher.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace embark_assist {
6868
embark_assist::defs::mid_level_tiles mlt;
6969
};
7070

71-
static states *state;
71+
static states *state = nullptr;
7272

7373
//=======================================================================================
7474

@@ -2731,6 +2731,7 @@ void embark_assist::matcher::setup() {
27312731

27322732
void embark_assist::matcher::shutdown() {
27332733
delete state;
2734+
state = nullptr;
27342735
}
27352736

27362737
//=======================================================================================

plugins/embark-assistant/survey.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace embark_assist {
7575
uint16_t max_inorganic;
7676
};
7777

78-
static states *state;
78+
static states *state = nullptr;
7979

8080
//=======================================================================================
8181

@@ -2548,5 +2548,6 @@ void embark_assist::survey::survey_embark(embark_assist::defs::mid_level_tiles *
25482548

25492549
void embark_assist::survey::shutdown() {
25502550
delete state;
2551+
state = nullptr;
25512552
}
25522553

0 commit comments

Comments
 (0)