Skip to content

Commit

Permalink
bugfix use-after-free error in building deconstruction.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChthonVII committed Apr 25, 2022
1 parent 2da0238 commit a51e048
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions REDALERT/BUILDING.CPP
Original file line number Diff line number Diff line change
Expand Up @@ -4391,6 +4391,9 @@ int BuildingClass::Mission_Deconstruction(void)
}
}
#endif
// Chthon CFE Note: Since this got moved, we need to save the House value here to avoid use-after-free later
HouseClass* memohouse = House;
bool wasownedbyplayer = IsOwnedByPlayer;
bool mcv_redeployed = false;

/*
Expand Down Expand Up @@ -4479,13 +4482,15 @@ int BuildingClass::Mission_Deconstruction(void)
#if 1
if (!mcv_redeployed)
{
if (IsOwnedByPlayer) {
//if (IsOwnedByPlayer) {
if (wasownedbyplayer) {
// Chthon CFE note: properly fix for MP
// also, this is totally use-after-free and Petroglyph just got lucky it wasn't blowing up on them
//if ((HouseClass *)House == PlayerPtr) {
// Speak(VOX_STRUCTURE_SOLD);
//}
if (House->IsHuman) {
Speak(VOX_STRUCTURE_SOLD, House);
if (memohouse->IsHuman) {
Speak(VOX_STRUCTURE_SOLD, memohouse);
}
}
}
Expand Down

0 comments on commit a51e048

Please sign in to comment.