]> granicus.if.org Git - poly2tri-c/commitdiff
Fix a memory leak in the P2trCDT constructor
authorBarak Itkin <lightningismyname@gmail.com>
Sun, 27 May 2012 18:10:39 +0000 (21:10 +0300)
committerBarak Itkin <lightningismyname@gmail.com>
Sun, 27 May 2012 18:10:39 +0000 (21:10 +0300)
refine/cdt.c
refine/mesh.c

index e0da6f225360de40eaf6859078f735cc6b189339..2ca9d82cdc44aaa68f2d01abdc9f6f4f4ce1081e 100644 (file)
@@ -55,6 +55,8 @@ p2tr_cdt_new (P2tCDT *cdt)
   P2tTrianglePtrArray cdt_tris = p2t_cdt_get_triangles (cdt);
   GHashTable *point_map = g_hash_table_new (g_direct_hash, g_direct_equal);
   P2trCDT *rmesh = g_slice_new (P2trCDT);
+  GHashTableIter iter;
+  P2trPoint *pt_iter = NULL;
 
   gint i, j;
 
@@ -129,6 +131,10 @@ p2tr_cdt_new (P2tCDT *cdt)
     p2tr_triangle_unref (new_tri);
   }
 
+  /* Now finally unref the points we added into the map */
+  g_hash_table_iter_init (&iter, point_map);
+  while (g_hash_table_iter_next (&iter, NULL, (gpointer*)&pt_iter))
+    p2tr_point_unref (pt_iter);
   g_hash_table_destroy (point_map);
 
   return rmesh;
index 9e951cd2203ef8737916e785ef8b357e816d350b..248290f8a3ed2d03a2c6489d00cd4c2f5b27186a 100644 (file)
@@ -23,7 +23,15 @@ P2trPoint*
 p2tr_mesh_new_point (P2trMesh          *self,
                      const P2trVector2 *c)
 {
-  P2trPoint *pt = p2tr_point_new (c);
+  return p2tr_mesh_new_point2 (self, c->x, c->y);
+}
+
+P2trPoint*
+p2tr_mesh_new_point2 (P2trMesh *self,
+                      gdouble   x,
+                      gdouble   y)
+{
+  P2trPoint *pt = p2tr_point_new2 (x, y);
 
   pt->mesh = self;
   p2tr_mesh_ref (self);
@@ -34,17 +42,6 @@ p2tr_mesh_new_point (P2trMesh          *self,
   return pt;
 }
 
-P2trPoint*
-p2tr_mesh_new_point2 (P2trMesh *self,
-                      gdouble   x,
-                      gdouble   y)
-{
-  P2trVector2 c;
-  c.x = x;
-  c.y = y;
-  return p2tr_mesh_new_point (self, &c);
-}
-
 P2trEdge*
 p2tr_mesh_new_edge (P2trMesh  *self,
                     P2trPoint *start,