Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use-after-free in do_attack #2185

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading