From: Barak Itkin Date: Sat, 28 Jul 2012 12:54:23 +0000 (+0300) Subject: Fix incorrect unref order on removing a triangle (caused memory errors) X-Git-Tag: p2tc-0.1.0~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c0da7471ce271a611575e415cc1db188eb673f1d;p=poly2tri-c Fix incorrect unref order on removing a triangle (caused memory errors) --- diff --git a/poly2tri-c/refine/triangle.c b/poly2tri-c/refine/triangle.c index 4625d98..6e05713 100644 --- a/poly2tri-c/refine/triangle.c +++ b/poly2tri-c/refine/triangle.c @@ -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); } }