[FWTools] OGRFeature memory problem?

Mateusz Łoskot mateusz at loskot.net
Mon May 15 09:12:23 EDT 2006


Mike Toothaker wrote:
> I will start off by apologizing for my lack of geospatial knowledge.
> I have just started a project and I am trying
> 
> to get caught up on the geospatial stuff as quickly as I can while 
> working with it.  We are using gdal in our project
> 
> and I have the following code(almost an exact copy paste from the
> gdal website). [...]

Hi Mike,

Please, read the OGR tutorial more carefully and you'll find
that your code is a bit different in case of memory deallocation.

> 
> delete poFeature;           //ß--- Error here
> 

Change this line to read as:

OGRFeature::DestroyFeature( poFeature );

On *Windows* , if you're using GDAL DLL (but not linking with static
library) then it's recommended to use dedicated Destroy* functions
instead of C++ 'delete' operator.
This is problem occurs on Windows because of crossing boundaries between
your application and GDAL DLL in case of memory allocation/deallocation.
The memory is allocated on DLL side (GetNextFeature()) but you're trying
to destroy it on your app side (delete operator) and that's incorrect on
Windwos platform.

I hope that will help.

Cheers
-- 
Mateusz Łoskot
http://mateusz.loskot.net


More information about the FWTools mailing list