Skip to content

Commit

Permalink
Fix use-after-free in do_attack
Browse files Browse the repository at this point in the history
The patch cf7e1bd had been applied improperly.
Follow upstream code.

Closes #2183.
  • Loading branch information
lmoureaux committed Feb 7, 2024
1 parent 12b2e65 commit b00a371
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions server/unithand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4134,8 +4134,7 @@ static bool do_attack(struct unit *punit, struct tile *def_tile,
/* Now that dead defender is certainly no longer listed as unit
* supported by the city, we may even remove the city
* (if it shrinks from size 1) */
auto pcity = tile_city(def_tile);
if (pdefender->hp <= 0) {
if (auto pcity = tile_city(def_tile); pcity != nullptr) {
unit_attack_civilian_casualties(punit, pcity, paction, "attack");
}
if (unit_is_alive(winner_id)) {
Expand Down

0 comments on commit b00a371

Please sign in to comment.