Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2003:
[Freeciv-Dev] catching pf_map memory leaks
Home

[Freeciv-Dev] catching pf_map memory leaks

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] catching pf_map memory leaks
From: Jason Short <jshort@xxxxxxxxxxxxxx>
Date: Wed, 22 Oct 2003 09:49:31 -0400
Reply-to: jdorje@xxxxxxxxxxxx

This patch will abort if PF leaks memory. And maybe some other times as well (it will abort if more than one PF map is used at a time). It's not recommended for committing but is helpful for debugging.

To make a permanent version of this patch we should probably just check that the number of maps is 0 at certain critical points. But that means a new PF interface function; probably not worth it.

jason
Index: common//aicore/path_finding.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/path_finding.c,v
retrieving revision 1.15
diff -u -r1.15 path_finding.c
--- common//aicore/path_finding.c       2003/10/21 21:49:55     1.15
+++ common//aicore/path_finding.c       2003/10/22 13:46:22
@@ -116,6 +116,10 @@
                                              int x, int y);
 static struct pf_path *danger_get_path(struct pf_map *pf_map, int x, int y);
 
+#ifdef DEBUG
+/* The total number of maps allocated.  Useful for debugging. */
+static int total_maps = 0;
+#endif
 
 /* =================== manipulating the cost ===================== */
 
@@ -410,6 +414,13 @@
     pf_map->d_lattice[pf_map->index].step = 0;
   }
 
+#ifdef DEBUG
+  total_maps++;
+
+  /* Not a hard limit, but currently it's not broken. */
+  assert(total_maps <= 1);
+#endif
+
   return pf_map;
 }
 
@@ -442,6 +453,11 @@
   }
 
   free(pf_map);
+
+#ifdef DEBUG
+  total_maps--;
+  assert(total_maps >= 0);
+#endif
 }
 
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] catching pf_map memory leaks, Jason Short <=