[geos-commits] r4100 - trunk/src/geomgraph
svn_geos at osgeo.org
svn_geos at osgeo.org
Sun Oct 4 07:09:49 PDT 2015
Author: mloskot
Date: 2015-10-04 07:09:49 -0700 (Sun, 04 Oct 2015)
New Revision: 4100
Modified:
trunk/src/geomgraph/PlanarGraph.cpp
Log:
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>.
Modified: trunk/src/geomgraph/PlanarGraph.cpp
===================================================================
--- trunk/src/geomgraph/PlanarGraph.cpp 2015-10-03 21:57:27 UTC (rev 4099)
+++ trunk/src/geomgraph/PlanarGraph.cpp 2015-10-04 14:09:49 UTC (rev 4100)
@@ -133,13 +133,12 @@
void
PlanarGraph::add(EdgeEnd* e)
{
+ assert(edgeEndList);
+ edgeEndList->push_back(e);
assert(e);
assert(nodes);
nodes->add(e);
-
- assert(edgeEndList);
- edgeEndList->push_back(e);
}
/*public*/
@@ -213,10 +212,20 @@
// by the ::add(EdgeEnd) call
DirectedEdge *de1=new DirectedEdge(e, true);
DirectedEdge *de2=new DirectedEdge(e, false);
-
de1->setSym(de2);
de2->setSym(de1);
- add(de1);
+
+ // ::add may throw, then de2 will not be registered for deletion
+ try
+ {
+ add(de1);
+ }
+ catch (...)
+ {
+ delete de2;
+ // no need to delete de1 which has already been registered in edgeEndList
+ throw;
+ }
add(de2);
}
}
More information about the geos-commits
mailing list