1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2026-03-14 17:19:43 +00:00

Fix two potential use-after-frees in monster's refcount code

This commit is contained in:
Joseph C. Sible
2025-12-25 17:42:00 -05:00
parent fbd6cce6a3
commit 566fc9f76a

View File

@@ -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()) {