From b63019eb43823cc6048c511020a86423700de8d3 Mon Sep 17 00:00:00 2001 From: Louis Moureaux Date: Wed, 31 Jan 2024 00:22:22 +0100 Subject: [PATCH] Fix use-after-free in do_attack The patch cf7e1bd2bc0d457bd17b7c10438fd73387112614 had been applied improperly. Follow upstream code. Closes #2183. --- server/unithand.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/unithand.cpp b/server/unithand.cpp index c4eddd9ecf..808281dc05 100644 --- a/server/unithand.cpp +++ b/server/unithand.cpp @@ -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)) {