[gdal-dev] [ogr_geometry.h ]Detected memory leaks when using c++ operator new

Frank Warmerdam warmerdam at pobox.com
Mon May 13 19:51:31 PDT 2013


梁天辰,

I am guessing you are working on Windows and are running into problems with
a mix of runtime heaps. I would suggest avoiding using new and delete
directly and instead leaving everything to functions from the GDAL DLL.

I believe you should use OGRGeometryFactory::createGeometry(wkbLinearRing)
to create the linear ring (use wkbPolygon for the polygon) and
OGRGeometryFactory::destroyGeometry() to destroy geometries.

Keep in mind that addRingDirectly() transfers ownership of the ring to the
polygon so you should not destroy the ring after that.  It will be cleaned
up by the polygon when that is destroyed.

Best regards,
Frank



On Mon, May 13, 2013 at 6:47 PM, 梁天辰 <2284168009 at qq.com> wrote:

> Hello all
>
> The following function uses c++ operator new to get a pointer of
> OGRLinearRing and modified that ring. Before the function returns, it's
> neccessary to delete that pointer,but  "delete poFLinear;" will cause a
> runtime error and the program stops running. What should I do to delete
> that pointer? Thanks.
>
>
> int GetWSInfo(const vector<Point> &ring,OUT CWSInfo & wsinfo)
> {
>  OGRLinearRing *poFLinear = new OGRLinearRing();
>  poFLinear->setPoints(ring.size(),(OGRRawPoint*)(&ring[0]));
>  poFLinear->closeRings();
>  OGRPolygon * poFPoly = new OGRPolygon();
>  poFPoly->addRingDirectly(poFLinear);
>  wsinfo.WSAREA = poFLinear->get_Area();
>  wsinfo.WSPERI = poFLinear->get_Length();
>  //delete poFLinear;
>  //delete poFPoly;
>  return RETURN_OK;
> }
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam,
warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Software Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130513/ebbbcbda/attachment.html>


More information about the gdal-dev mailing list