From db4db82fdde12ae6a95c616c1708f8e43462597b Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 30 Sep 2021 16:47:03 +0300 Subject: [PATCH 41/41] Free rally points when the city is destroyed See osdn #42953 Signed-off-by: Marko Lindqvist --- common/city.c | 19 +++++++++++++++++++ common/city.h | 2 ++ server/cityturn.c | 6 +----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/common/city.c b/common/city.c index 109d5644ac..a6fccb9241 100644 --- a/common/city.c +++ b/common/city.c @@ -3354,6 +3354,7 @@ void destroy_city_virtual(struct city *pcity) citizens_free(pcity); + /* Free worker tasks */ while (worker_task_list_size(pcity->task_reqs) > 0) { struct worker_task *ptask = worker_task_list_get(pcity->task_reqs, 0); @@ -3363,6 +3364,9 @@ void destroy_city_virtual(struct city *pcity) } worker_task_list_destroy(pcity->task_reqs); + /* Free rally points */ + city_rally_point_clear(pcity); + unit_list_destroy(pcity->units_supported); trade_route_list_destroy(pcity->routes); if (pcity->tile_cache != NULL) { @@ -3444,3 +3448,18 @@ void city_set_ai_data(struct city *pcity, const struct ai_type *ai, { pcity->server.ais[ai_type_number(ai)] = data; } + +/**********************************************************************//** + Clear rally point set for the city. +**************************************************************************/ +void city_rally_point_clear(struct city *pcity) +{ + /* Free rally points */ + if (pcity->rally_point.length > 0) { + pcity->rally_point.length = 0; + pcity->rally_point.persistent = FALSE; + pcity->rally_point.vigilant = FALSE; + free(pcity->rally_point.orders); + pcity->rally_point.orders = NULL; + } +} diff --git a/common/city.h b/common/city.h index c01d55c6f6..d61b60d694 100644 --- a/common/city.h +++ b/common/city.h @@ -805,6 +805,8 @@ void *city_ai_data(const struct city *pcity, const struct ai_type *ai); void city_set_ai_data(struct city *pcity, const struct ai_type *ai, void *data); +void city_rally_point_clear(struct city *pcity); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/server/cityturn.c b/server/cityturn.c index ab6487dda6..19ada19369 100644 --- a/server/cityturn.c +++ b/server/cityturn.c @@ -2588,11 +2588,7 @@ static bool city_build_unit(struct player *pplayer, struct city *pcity) if (city_exist(saved_city_id)) { if (pcity->rally_point.length && !pcity->rally_point.persistent) { - pcity->rally_point.length = 0; - pcity->rally_point.persistent = FALSE; - pcity->rally_point.vigilant = FALSE; - free(pcity->rally_point.orders); - pcity->rally_point.orders = NULL; + city_rally_point_clear(pcity); } /* Done building this unit; time to move on to the next. */ -- 2.33.0