[Mapserver-dev] memory leak in mapogr.cpp

Frank Warmerdam warmerdam at pobox.com
Fri May 28 15:02:05 EDT 2004


Mladen Turk wrote:
> Hi all,
> 
> There is a memory leak in mapogr.cpp.
> 
> The reason is quite simple and obvious when using gdal as dll, and it
> involves operator delete on a memory that has been allocated using
> OGRSFDriverRegistrar::Open in a gdal dll, that has a different memory heap.
> 
> Not sure how to resolve this, but something like 
> 
> void GDALDelete(void *p)
> {
>    delete p;
> }
> 
> Inside the gdal itself should be called instead simply calling delete from
> mapserver or mapscript. 

Mladen,

In fact, this is generally worse than just a memory leak ... it is a heap
corruption.  Can you point out the particular places this is occuring?  Skimming
the mapogr.cpp I can see a number of questionable uses of delete likely to
cause problems.

There are "destructor" methods for most types in OGR.  For instance,
the OGRFeature::DestroyFeature( poFeature ) static method can be used to
destroy features within the GDAL DLL itself.

In a normal (old style) MapServer build on windows, the OGR code is
actually statically linked in as well as being in the DLL so this might
not cause any problems.  But as we move to using GDAL/OGR purely from the
DLL with no static libraries it becomes a more serious bug.

I have taken liberty of creating a bug report on the issue:

   http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=697

Followup there.

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 mapserver-dev mailing list