From 15729c74f0542aea6828ccfb83d49a89eaa7fa9e Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Fri, 2 Oct 2009 01:30:12 -0800 Subject: [PATCH] Fix two gross memory leaks. I was neglecting to clear the SEdgeList that I created in SPolygon::SelfIntersecting, and while triangulating a polygon I would free the SContour, but not the list of points associated with the contour. [git-p4: depot-paths = "//depot/solvespace/": change = 2047] --- polygon.cpp | 9 +++++++-- srf/triangulate.cpp | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/polygon.cpp b/polygon.cpp index 9f1bafd..9a6eba3 100644 --- a/polygon.cpp +++ b/polygon.cpp @@ -562,12 +562,17 @@ bool SPolygon::SelfIntersecting(Vector *intersectsAt) { ZERO(&el); MakeEdgesInto(&el); + bool ret = false; SEdge *se; for(se = el.l.First(); se; se = el.l.NextAfter(se)) { int inters = el.AnyEdgeCrossings(se->a, se->b, intersectsAt); - if(inters != 1) return true; + if(inters != 1) { + ret = true; + break; + } } - return false; + el.Clear(); + return ret; } static int TriMode, TriVertexCount; diff --git a/srf/triangulate.cpp b/srf/triangulate.cpp index 8813292..e5c3dd3 100644 --- a/srf/triangulate.cpp +++ b/srf/triangulate.cpp @@ -89,6 +89,13 @@ void SPolygon::UvTriangulateInto(SMesh *m, SSurface *srf) { el.Clear(); vl.Clear(); + // Careful, need to free the points within the contours, and not just + // the contours themselves. This was a tricky memory leak. + for(sc = l.First(); sc; sc = l.NextAfter(sc)) { + if(sc->tag) { + sc->l.Clear(); + } + } l.RemoveTagged(); } }