]> granicus.if.org Git - poly2tri-c/commitdiff
Fix incorrect unref order on removing a triangle (caused memory errors)
authorBarak Itkin <lightningismyname@gmail.com>
Sat, 28 Jul 2012 12:54:23 +0000 (15:54 +0300)
committerBarak Itkin <lightningismyname@gmail.com>
Sat, 28 Jul 2012 12:54:23 +0000 (15:54 +0300)
poly2tri-c/refine/triangle.c

index 4625d989bcb623e50f016029a4909bec3d3ea02f..6e05713fa8763e9c12e1c2cce00634e72adc77d5 100644 (file)
@@ -166,10 +166,12 @@ p2tr_triangle_remove (P2trTriangle *self)
   for (i = 0; i < 3; i++)
   {
     self->edges[i]->tri = NULL;
-    p2tr_triangle_unref (self);
-
     p2tr_edge_unref (self->edges[i]);
     self->edges[i] = NULL;
+    /* Although we lost reference to the triangle 3 rows above, we must
+     * not unref it untill here since we still use the struct until this
+     * line! */
+    p2tr_triangle_unref (self);
   }
 }