From e2e93bc4aa05a9491f597f1caee147e5fbd9f926 Mon Sep 17 00:00:00 2001 From: sveinung Date: Thu, 11 May 2017 06:25:25 +0000 Subject: [PATCH] Fix trade route memory leak. Free the memory of the trade route structs canceled by the destruction of a city or player. Reported by Valgrind. See hrm Bug #658824 git-svn-id: svn://svn.gna.org/svn/freeciv/trunk@35499 a0f10bec-cc02-0410-94fc-a9cfff90b4cd --- server/citytools.c | 6 +++++- server/plrhand.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/citytools.c b/server/citytools.c index 8306d5b6a3..8dd4114ea5 100644 --- a/server/citytools.c +++ b/server/citytools.c @@ -1743,7 +1743,11 @@ void remove_city(struct city *pcity) } trade_routes_iterate_safe(pcity, proute) { - remove_trade_route(pcity, proute, TRUE, TRUE); + struct trade_route *pback = remove_trade_route(pcity, proute, + TRUE, TRUE); + + FC_FREE(proute); + FC_FREE(pback); } trade_routes_iterate_safe_end; map_clear_border(pcenter); diff --git a/server/plrhand.c b/server/plrhand.c index f76babbe6c..11a0bf45f6 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -1714,7 +1714,11 @@ void server_remove_player(struct player *pplayer) * to point to a city removed by player_clear() */ city_list_iterate(pplayer->cities, pcity) { trade_routes_iterate_safe(pcity, proute) { - remove_trade_route(pcity, proute, TRUE, TRUE); + struct trade_route *pback = remove_trade_route(pcity, proute, + TRUE, TRUE); + + FC_FREE(proute); + FC_FREE(pback); } trade_routes_iterate_safe_end; } city_list_iterate_end; -- 2.11.4.GIT