[geos-commits] r2368 - in trunk/source: headers/geos/geom headers/geos/geom/util precision

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Apr 15 06:02:02 EDT 2009


Author: strk
Date: 2009-04-15 06:02:01 -0400 (Wed, 15 Apr 2009)
New Revision: 2368

Modified:
   trunk/source/headers/geos/geom/CoordinateSequence.h
   trunk/source/headers/geos/geom/util/CoordinateOperation.h
   trunk/source/precision/SimpleGeometryPrecisionReducer.cpp
Log:
Fix leak in SimpleGeometryPrecisionReducer, improve memory management docs where topic.


Modified: trunk/source/headers/geos/geom/CoordinateSequence.h
===================================================================
--- trunk/source/headers/geos/geom/CoordinateSequence.h	2009-04-15 09:29:52 UTC (rev 2367)
+++ trunk/source/headers/geos/geom/CoordinateSequence.h	2009-04-15 10:02:01 UTC (rev 2368)
@@ -217,6 +217,8 @@
 	///
 	/// Equality test is 2D based
 	///
+	/// Ownership of returned object goes to the caller.
+	///
 	static CoordinateSequence* removeRepeatedPoints(
 			const CoordinateSequence *cl);
 

Modified: trunk/source/headers/geos/geom/util/CoordinateOperation.h
===================================================================
--- trunk/source/headers/geos/geom/util/CoordinateOperation.h	2009-04-15 09:29:52 UTC (rev 2367)
+++ trunk/source/headers/geos/geom/util/CoordinateOperation.h	2009-04-15 10:02:01 UTC (rev 2368)
@@ -43,7 +43,7 @@
 public:
 
 	/**
-	 * Return a newly created geometry 
+	 * Return a newly created geometry, ownership to caller
 	 */
 	virtual Geometry* edit(const Geometry *geometry,
 			const GeometryFactory *factory);

Modified: trunk/source/precision/SimpleGeometryPrecisionReducer.cpp
===================================================================
--- trunk/source/precision/SimpleGeometryPrecisionReducer.cpp	2009-04-15 09:29:52 UTC (rev 2367)
+++ trunk/source/precision/SimpleGeometryPrecisionReducer.cpp	2009-04-15 10:02:01 UTC (rev 2368)
@@ -39,22 +39,33 @@
 namespace geos {
 namespace precision { // geos.precision
 
-class PrecisionReducerCoordinateOperation: public geom::util::CoordinateOperation {
+class PrecisionReducerCoordinateOperation :
+		public geom::util::CoordinateOperation
+{
 using CoordinateOperation::edit;
 private:
+
 	SimpleGeometryPrecisionReducer *sgpr;
+
 public:
-	PrecisionReducerCoordinateOperation(SimpleGeometryPrecisionReducer *newSgpr);
-	CoordinateSequence* edit(const CoordinateSequence *coordinates, const Geometry *geom);
+
+	PrecisionReducerCoordinateOperation(
+		SimpleGeometryPrecisionReducer *newSgpr);
+
+	/// Ownership of returned CoordinateSequence to caller
+	CoordinateSequence* edit(const CoordinateSequence *coordinates,
+	                         const Geometry *geom);
 };
 
-PrecisionReducerCoordinateOperation::PrecisionReducerCoordinateOperation(SimpleGeometryPrecisionReducer *newSgpr)
+PrecisionReducerCoordinateOperation::PrecisionReducerCoordinateOperation(
+		SimpleGeometryPrecisionReducer *newSgpr)
 {
 	sgpr=newSgpr;
 }
 
 CoordinateSequence*
-PrecisionReducerCoordinateOperation::edit(const CoordinateSequence *cs, const Geometry *geom)
+PrecisionReducerCoordinateOperation::edit(const CoordinateSequence *cs,
+                                          const Geometry *geom)
 {
 	if (cs->getSize()==0) return NULL;
 
@@ -70,26 +81,35 @@
 		(*vc)[i] = coord;
 	}
 
-	CoordinateSequence *reducedCoords = geom->getFactory()->getCoordinateSequenceFactory()->create(vc);
+	// reducedCoords take ownership of 'vc'
+	CoordinateSequence *reducedCoords =
+		geom->getFactory()->getCoordinateSequenceFactory()->create(vc);
 
-	// remove repeated points, to simplify returned geometry as much as possible
+	// remove repeated points, to simplify returned geometry as
+	// much as possible.
+	// 
 	CoordinateSequence *noRepeatedCoords=CoordinateSequence::removeRepeatedPoints(reducedCoords);
 
 	/**
-	* Check to see if the removal of repeated points
-	* collapsed the coordinate List to an invalid length
-	* for the type of the parent geometry.
-	* It is not necessary to check for Point collapses, since the coordinate list can
-	* never collapse to less than one point.
-	* If the length is invalid, return the full-length coordinate array
-	* first computed, or null if collapses are being removed.
-	* (This may create an invalid geometry - the client must handle this.)
-	*/
+	 * Check to see if the removal of repeated points
+	 * collapsed the coordinate List to an invalid length
+	 * for the type of the parent geometry.
+	 * It is not necessary to check for Point collapses,
+	 * since the coordinate list can
+	 * never collapse to less than one point.
+	 * If the length is invalid, return the full-length coordinate array
+	 * first computed, or null if collapses are being removed.
+	 * (This may create an invalid geometry - the client must handle this.)
+	 */
 	unsigned int minLength = 0;
 	if (typeid(*geom)==typeid(LineString)) minLength = 2;
 	if (typeid(*geom)==typeid(LinearRing)) minLength = 4;
 	CoordinateSequence *collapsedCoords = reducedCoords;
-	if (sgpr->getRemoveCollapsed()) collapsedCoords=NULL;
+	if (sgpr->getRemoveCollapsed())
+	{
+		delete reducedCoords; reducedCoords=0;
+		collapsedCoords=0;
+	}
 	// return null or orginal length coordinate array
 	if (noRepeatedCoords->getSize()<minLength) {
 		delete noRepeatedCoords;



More information about the geos-commits mailing list