[gdal-dev] Heap Corruption

Joel Odom joelodom at gmail.com
Wed Oct 22 10:34:59 EDT 2008


Frank, this was the problem.  Thanks for your help.
For the list archives, here is another working sample (essentially the same
as what Frank put below).

OGRPoint* p = (OGRPoint*)OGRGeometryFactory::createGeometry(wkbPoint);
p->setX(3.141);
p->setY(2.718);
OGRGeometryFactory::destroyGeometry(p);




On Wed, Oct 22, 2008 at 10:23 AM, Frank Warmerdam <warmerdam at pobox.com>wrote:

> 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
>
>


-- 
http://giscoder.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20081022/553922f3/attachment.html


More information about the gdal-dev mailing list