Author: sveinung
Date: Thu May 11 08:25:25 2017
New Revision: 35499

URL: http://svn.gna.org/viewcvs/freeciv?rev=35499&view=rev
Log:
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

Modified:
    trunk/server/citytools.c
    trunk/server/plrhand.c

Modified: trunk/server/citytools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/citytools.c?rev=35499&r1=35498&r2=35499&view=diff
==============================================================================
--- trunk/server/citytools.c    (original)
+++ trunk/server/citytools.c    Thu May 11 08:25:25 2017
@@ -1743,7 +1743,11 @@
   }
 
   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);

Modified: trunk/server/plrhand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/plrhand.c?rev=35499&r1=35498&r2=35499&view=diff
==============================================================================
--- trunk/server/plrhand.c      (original)
+++ trunk/server/plrhand.c      Thu May 11 08:25:25 2017
@@ -1714,7 +1714,11 @@
    * 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;
 


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to