From: awaw fumin Date: Wed, 2 Apr 2014 23:41:28 +0000 (+0300) Subject: cherry-pick the relevant parts of commit dd3660fd4418 from the GEGL copy of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=43e553f7aaffc0f471f029aff5f046e492107df8;p=poly2tri-c cherry-pick the relevant parts of commit dd3660fd4418 from the GEGL copy of the library [PATCH] operations: Fix memory leaks in seamless clone The leaks detected and fixed herein were discovered using the "Leaks" template in Apple's "Instruments" tool. At least according to Instruments, there are completely no leaks anymore after applying the fixes in this commit. --- diff --git a/poly2tri-c/refine/cdt.c b/poly2tri-c/refine/cdt.c index 7dc1d11..4929d34 100644 --- a/poly2tri-c/refine/cdt.c +++ b/poly2tri-c/refine/cdt.c @@ -319,6 +319,8 @@ p2tr_cdt_insert_point (P2trCDT *self, GList *parts = p2tr_cdt_split_edge (self, edge, pt), *eIter; for (eIter = parts; eIter != NULL; eIter = eIter->next) p2tr_edge_unref ((P2trEdge*)eIter->data); + g_list_free(parts); + inserted = TRUE; break; } diff --git a/poly2tri-c/refine/cluster.c b/poly2tri-c/refine/cluster.c index 3e6ce25..ba04435 100644 --- a/poly2tri-c/refine/cluster.c +++ b/poly2tri-c/refine/cluster.c @@ -81,7 +81,7 @@ p2tr_cluster_get_for (P2trPoint *P, g_queue_push_head (&cluster->edges, p2tr_edge_ref (E)); - current = E; + current = p2tr_edge_ref (E); next = p2tr_point_edge_cw (P, current); while (next != g_queue_peek_head (&cluster->edges) @@ -89,22 +89,29 @@ p2tr_cluster_get_for (P2trPoint *P, && p2tr_cluster_cw_tri_between_is_in_domain (current, next)) { g_queue_push_tail (&cluster->edges, p2tr_edge_ref (next)); + p2tr_edge_unref (current); current = next; next = p2tr_point_edge_cw (P, current); cluster->min_angle = MIN (cluster->min_angle, temp_angle); } + p2tr_edge_unref (current); + p2tr_edge_unref (next); - current = E; + current = p2tr_edge_ref (E); next = p2tr_point_edge_ccw(P, current); + p2tr_edge_unref(next); while (next != g_queue_peek_tail (&cluster->edges) && (temp_angle = p2tr_edge_angle_between (current->mirror, next)) <= P2TR_CLUSTER_LIMIT_ANGLE && p2tr_cluster_cw_tri_between_is_in_domain (next, current)) { g_queue_push_head (&cluster->edges, p2tr_edge_ref (next)); + p2tr_edge_unref (current); current = next; next = p2tr_point_edge_ccw (P, current); cluster->min_angle = MIN(cluster->min_angle, temp_angle); } + p2tr_edge_unref (current); + p2tr_edge_unref (next); return cluster; } diff --git a/poly2tri-c/refine/delaunay-terminator.c b/poly2tri-c/refine/delaunay-terminator.c index 48ff030..1de1fea 100644 --- a/poly2tri-c/refine/delaunay-terminator.c +++ b/poly2tri-c/refine/delaunay-terminator.c @@ -105,6 +105,8 @@ p2tr_cdt_get_segments_encroached_by (P2trCDT *self, * since it's still faster */ if (e->constrained && p2tr_cdt_is_encroached (e)) p2tr_vedge_set_add2 (encroached, p2tr_vedge_new2 (e)); + + p2tr_edge_unref(e); } return encroached; @@ -431,6 +433,9 @@ SplitEncroachedSubsegments (P2trDelaunayTerminator *self, gdouble theta, P2trTri p2tr_dt_enqueue_segment (self, e); p2tr_edge_unref (e); } + + g_list_free(parts); + p2tr_point_unref(Pv); } p2tr_edge_unref (s); } diff --git a/poly2tri-c/refine/mesh.c b/poly2tri-c/refine/mesh.c index bbeadd3..7fc192f 100644 --- a/poly2tri-c/refine/mesh.c +++ b/poly2tri-c/refine/mesh.c @@ -200,11 +200,11 @@ p2tr_mesh_action_group_commit (P2trMesh *self) g_assert (self->record_undo); + self->record_undo = FALSE; + for (iter = self->undo.head; iter != NULL; iter = iter->next) p2tr_mesh_action_unref ((P2trMeshAction*)iter->data); g_queue_clear (&self->undo); - - self->record_undo = FALSE; } void @@ -214,14 +214,16 @@ p2tr_mesh_action_group_undo (P2trMesh *self) g_assert (self->record_undo); + /* Set the record_undo flag to FALSE before p2tr_mesh_action_undo, so that + * we don't create zombie objects therein. */ + self->record_undo = FALSE; + for (iter = self->undo.tail; iter != NULL; iter = iter->prev) { p2tr_mesh_action_undo ((P2trMeshAction*)iter->data, self); p2tr_mesh_action_unref ((P2trMeshAction*)iter->data); } g_queue_clear (&self->undo); - - self->record_undo = FALSE; } void