[geos-commits] r4105 - in branches/3.5: . src/geomgraph tests/unit/triangulate

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Oct 5 02:44:36 PDT 2015


Author: mloskot
Date: 2015-10-05 02:44:36 -0700 (Mon, 05 Oct 2015)
New Revision: 4105

Modified:
   branches/3.5/
   branches/3.5/src/geomgraph/PlanarGraph.cpp
   branches/3.5/tests/unit/triangulate/DelaunayTest.cpp
Log:
Merged revision(s) 4099-4100, 4104 from trunk:
Fix memory leaks (two) due to misuse of CoordinateArraySequence
........
Make adding edges a bit more exception safe and helps to avoid memory leaks when PlanarGraph::add(de1) throws, leaving de2 behind.
This also fixes memory leak in case of self-union with NaN coordinates, revealed by GEOSUnaryUnionTest/test<9>.
........
Use std::auto_ptr to simplify r4100 fix of a memory leak potential
........



Property changes on: branches/3.5
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/3.4:4056
   + /branches/3.4:4056
/trunk:4099-4100,4104

Modified: branches/3.5/src/geomgraph/PlanarGraph.cpp
===================================================================
--- branches/3.5/src/geomgraph/PlanarGraph.cpp	2015-10-05 09:38:40 UTC (rev 4104)
+++ branches/3.5/src/geomgraph/PlanarGraph.cpp	2015-10-05 09:44:36 UTC (rev 4105)
@@ -133,13 +133,14 @@
 void
 PlanarGraph::add(EdgeEnd* e)
 {
+	// It is critical to add the edge to the edgeEndList first,
+	// then it is safe to follow with any potentially throwing operations.
+	assert(edgeEndList);
+	edgeEndList->push_back(e);
 
 	assert(e);
 	assert(nodes);
 	nodes->add(e);
-
-	assert(edgeEndList);
-	edgeEndList->push_back(e);
 }
 
 /*public*/
@@ -211,13 +212,14 @@
 		// PlanarGraph destructor will delete all DirectedEdges 
 		// in edgeEndList, which is where these are added
 		// by the ::add(EdgeEnd) call
-		DirectedEdge *de1=new DirectedEdge(e, true);
-		DirectedEdge *de2=new DirectedEdge(e, false);
+		std::auto_ptr<DirectedEdge> de1(new DirectedEdge(e, true));
+		std::auto_ptr<DirectedEdge> de2(new DirectedEdge(e, false));
+		de1->setSym(de2.get());
+		de2->setSym(de1.get());
 
-		de1->setSym(de2);
-		de2->setSym(de1);
-		add(de1);
-		add(de2);
+		// First, ::add takes the ownership, then follows with operations that may throw.
+		add(de1.release());
+		add(de2.release());
 	}
 }
 

Modified: branches/3.5/tests/unit/triangulate/DelaunayTest.cpp
===================================================================
--- branches/3.5/tests/unit/triangulate/DelaunayTest.cpp	2015-10-05 09:38:40 UTC (rev 4104)
+++ branches/3.5/tests/unit/triangulate/DelaunayTest.cpp	2015-10-05 09:44:36 UTC (rev 4105)
@@ -181,14 +181,12 @@
 		v->push_back( Coordinate (150,200) );
 		v->push_back( Coordinate (180,270) );
 		v->push_back( Coordinate (275,163) );
+		geos::geom::CoordinateArraySequence seq(v);
 
-		geos::geom::CoordinateArraySequence *seq = new CoordinateArraySequence(v);
+		Envelope env = DelaunayTriangulationBuilder::envelope(seq);
 
-		Envelope env = DelaunayTriangulationBuilder::envelope(*seq);
-
 		ensure_equals(env.getWidth() , 125);
 		ensure_equals(env.getHeight() , 107);
-
 	}
 
 } // namespace tut



More information about the geos-commits mailing list