mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2026-03-12 16:19:43 +00:00
Merge pull request #492 from josephcsible/fixref
Fix two potential use-after-frees in monster's refcount code
This commit is contained in:
18
shmup.cpp
18
shmup.cpp
@@ -83,15 +83,10 @@ struct monster {
|
||||
|
||||
void rebasePat(const shiftmatrix& new_pat, cell *tgt);
|
||||
|
||||
void remove_reference() {
|
||||
refs--;
|
||||
if(!refs) {
|
||||
if(parent) parent->remove_reference();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
void remove_reference();
|
||||
|
||||
void set_parent(monster *par) {
|
||||
if(parent == par) return;
|
||||
if(parent) parent->remove_reference();
|
||||
parent = par;
|
||||
parent->refs++;
|
||||
@@ -128,6 +123,15 @@ typedef multimap<cell*, monster*>::iterator mit;
|
||||
|
||||
EX vector<monster*> active, nonvirtual, additional;
|
||||
|
||||
void monster::remove_reference() {
|
||||
refs--;
|
||||
if(!refs) {
|
||||
if(parent) parent->remove_reference();
|
||||
nonvirtual.erase(std::remove(nonvirtual.begin(), nonvirtual.end(), this), nonvirtual.end());
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
cell *findbaseAround(shiftpoint p, cell *around, int maxsteps) {
|
||||
|
||||
if(quotient || fake::split()) {
|
||||
|
||||
Reference in New Issue
Block a user