Hi Folks, Spent a few hours today tracking down a few memory leaks in the geos buffer code. Two of the leaks are visible by running valgrind against docs/example.cpp.
I've attached a patch against HEAD that fixes it. Regards, Robert Coup -- One Track Mind Ltd. PO Box 1604, Shortland St, Auckland, New Zealand Phone +64-9-966 0433 Fax +64-9-969 0045 Web http://www.onetrackmind.co.nz
Index: source/operation/buffer/OffsetCurveSetBuilder.cpp =================================================================== --- source/operation/buffer/OffsetCurveSetBuilder.cpp (revision 1997) +++ source/operation/buffer/OffsetCurveSetBuilder.cpp (working copy) @@ -69,7 +69,10 @@ { //delete cga; for (size_t i=0, n=curveList.size(); i<n; ++i) + { + delete curveList[i]->getCoordinates(); delete curveList[i]; + } for (size_t i=0, n=newLabels.size(); i<n; ++i) delete newLabels[i]; } @@ -107,12 +110,13 @@ #if GEOS_DEBUG std::cerr<<" skipped (size<2)"<<std::endl; #endif + delete coord; return; } // add the edge for a coordinate list which is a raw offset curve Label *newlabel = new Label(0, Location::BOUNDARY, leftLoc, rightLoc); - SegmentString *e=new SegmentString(coord, newlabel); + SegmentString *e=new SegmentString(coord, newlabel); // SegmentString doesnt own the sequence, so we need to delete in the destructor newLabels.push_back(newlabel); curveList.push_back(e); } Index: source/operation/buffer/BufferBuilder.cpp =================================================================== --- source/operation/buffer/BufferBuilder.cpp (revision 1997) +++ source/operation/buffer/BufferBuilder.cpp (working copy) @@ -270,8 +270,11 @@ const Label* oldLabel = static_cast<const Label*>(segStr->getData()); CoordinateSequence* cs = CoordinateSequence::removeRepeatedPoints(segStr->getCoordinates()); - if ( cs->size() < 2 ) return; // don't insert collapsed edges - + if ( cs->size() < 2 ) + { + delete cs; // we need to take care of the memory here as cs is a new sequence + return; // don't insert collapsed edges + } // we need to clone SegmentString coordinates // as Edge will take ownership of them // TODO: find a way to transfer ownership instead Index: source/operation/buffer/OffsetCurveVertexList.h =================================================================== --- source/operation/buffer/OffsetCurveVertexList.h (revision 1997) +++ source/operation/buffer/OffsetCurveVertexList.h (working copy) @@ -54,6 +54,7 @@ private: geom::CoordinateSequence* ptList; + bool ptListConsumed; const geom::PrecisionModel* precisionModel; @@ -89,6 +90,7 @@ OffsetCurveVertexList() : ptList(new geom::CoordinateArraySequence()), + ptListConsumed(false), precisionModel(NULL), minimumVertexDistance (0.0) { @@ -96,6 +98,8 @@ ~OffsetCurveVertexList() { + if (!ptListConsumed) + delete ptList; } void setPrecisionModel(const geom::PrecisionModel* nPrecisionModel) @@ -140,6 +144,7 @@ geom::CoordinateSequence* getCoordinates() { closeRing(); + ptListConsumed = true; return ptList; }
_______________________________________________ geos-devel mailing list geos-devel@geos.refractions.net http://geos.refractions.net/mailman/listinfo/geos-devel