<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39500 >

On 07/08/2007, Marko Lindqvist <[EMAIL PROTECTED]> wrote:
>
>  Found by valgrind.
>
>  Applies to trunk, S2_1 and S2_0. Tested only in trunk (If *path is
> not initially sane value (such as NULL), this patch may lead to crash)

 It is safe for all branches.

 Attached version adds assert() that makes sure that it also remains
safe. This version should go in to trunk, stable branches should use
previous version.


 - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c	2007-08-05 14:35:10.000000000 +0300
+++ freeciv/ai/aiferry.c	2007-08-08 20:20:52.000000000 +0300
@@ -393,6 +393,14 @@
   struct pf_map *search_map;
   int ferryboat = punit->ai.ferryboat; /*currently assigned ferry*/
 
+  /* We may end calling pf_destroy_path for *path if it's not NULL.
+   * Most likely you are passing garbage or path you don't want
+   * destroyed if this assert fails.
+   * Don't try to be clever and pass 'fallback' path that will be returned
+   * if no path is found. Instead check for NULL return value and then
+   * use fallback path in calling function. */
+  assert(path == NULL || *path == NULL);
+
   assert(0 < ferryboat
 	 || FERRY_NONE == ferryboat
 	 || FERRY_WANTED == ferryboat);
@@ -445,6 +453,9 @@
 		     aunit->tile->y,
 		     aunit->moves_left);
 	    if (path) {
+             if (*path) {
+                pf_destroy_path(*path);
+              }
 	      *path = pf_next_get_path(search_map);
 	    }
             best_turns = turns;
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to