Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2004:
[Freeciv-Dev] (PR#10613) PF memory leak
Home

[Freeciv-Dev] (PR#10613) PF memory leak

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10613) PF memory leak
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 21 Oct 2004 10:14:16 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10613 >

In fact this bug is inside PF.  When iterating over a danger map
sometimes the danger segment for a node will be allocated multiple times.

I really have no idea what's going on here (though I haven't looked
closely).  Is there supposed to be one danger segment for each direction
(currently there is just one per node)?  Or are we erronously
initializing the danger data for the node more than once?

This patch "fixes" the problem by freeing the data before allocating it
a second time.  Replace this check with an assert and you can see the
bug in action.  The patch fixes the leak without breaking anything...but
there's a pretty good chance the current behavior is buggy.

jason

Index: common/aicore/path_finding.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/path_finding.c,v
retrieving revision 1.24
diff -u -r1.24 path_finding.c
--- common/aicore/path_finding.c        30 Sep 2004 15:13:58 -0000      1.24
+++ common/aicore/path_finding.c        21 Oct 2004 17:11:45 -0000
@@ -770,6 +770,9 @@
   struct pf_node *node = &pf_map->lattice[ptile->index];
 
   /* Allocating memory */
+  if (d_node1->danger_segment) {
+    free(d_node1->danger_segment);
+  }
   d_node1->danger_segment = fc_malloc(length * sizeof(struct pf_danger_pos));
 
   /* Now fill the positions */

[Prev in Thread] Current Thread [Next in Thread]