[gdal-dev] Heap Corruption

Frank Warmerdam warmerdam at pobox.com
Wed Oct 22 10:23:24 EDT 2008


Joel Odom wrote:
> Anybody knows why these two lines of code cause corruption on the heap? 
>  Thanks.
> 
> OGRPoint* ogr_point = new OGRPoint(5.0, 5.0);
> delete ogr_point;

Joel,

My guess is that you are doing this "cross heap".  Are you running on windows?
Do you build your application calling OGR with /MD?  If not your application
code may have a distinct heap from the GDAL DLL and this makes it very hard
to safely create and destroy c++ objects using new and delete.

Assuming you don't want to harmonize the heap, the normal solution is to
ensure creation and destruction are done within the DLL.  So change to
something like:

   OGRPoint *ogr_point = (OGRPoint *)
            OGRGeometryFactory::createGeometry( wkbPoint );

   ogr_point->setX( 5.0 );
   ogr_point->setY( 5.0 );

   ...

   OGRGeometryFactory::destroyGeometry( ogr_point );

Best regards,
-- 
---------------------------------------+--------------------------------------
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 Programmer for Rent



More information about the gdal-dev mailing list