[Gdal-dev] Memory leak? How to release GDAL datasets?

Craig Miller craig.miller at spatialminds.com
Fri Dec 15 20:51:21 EST 2006


Frank,

Here is a bit more info:

I'm working on an old project and some of my project settings were messed up
resulting in an old build of gdal getting used.  I'm no longer seeing the
weird Ogrpolygon stuff.  Unfortunately, once I fixed that I'm seeing a few
different potential problems.  Here is the call stack and Data for the first
two.

------------
Mapcanvas.cpp line 104 looks like this:
m_pDataset = (GDALDataset *) GDALOpen( m_strFilename, GA_ReadOnly );

In my destructor I call:
if (m_pDataset != NULL)
{
	GDALClose(m_pDataset);
	m_pDataset = NULL;
}

Call Stack:
    c:\vault\gdal\port\cpl_vsisimple.cpp (343): VSIRealloc
    c:\vault\gdal\port\cpl_conv.cpp (363): CPLRealloc
    c:\vault\gdal\gcore\gdaldataset.cpp (180): GDALDataset::GDALDataset
    c:\vault\gdal\gcore\gdalpamdataset.cpp (107):
GDALPamDataset::GDALPamDataset
    c:\vault\gdal\frmts\gtiff\geotiff.cpp (1580): GTiffDataset::GTiffDataset
    c:\vault\gdal\frmts\gtiff\geotiff.cpp (2594): GTiffDataset::Open
    c:\vault\gdal\gcore\gdaldataset.cpp (1714): GDALOpen
    c:\vault\backroads\mapcanvas.cpp (104): CMapCanvas::Open
 Data:
    88 B5 5B 01    E0 BD 2B 04                                   ..[...+.
........


------------------
Mapcanvas.cpp line 324 looks like this:
switch (pBand->GetColorInterpretation())

I don't free the ColorInterpretation as I understand it to be owned by the
band.

 Call Stack:
    c:\vault\gdal\port\cpl_vsisimple.cpp (333): VSIMalloc
    c:\vault\gdal\gcore\gdalrasterblock.cpp (433):
GDALRasterBlock::Internalize
    c:\vault\gdal\gcore\gdalrasterband.cpp (1150):
GDALRasterBand::GetLockedBlockRef
    c:\vault\gdal\gcore\rasterio.cpp (386): GDALRasterBand::IRasterIO
    c:\vault\gdal\gcore\gdalrasterband.cpp (308): GDALRasterBand::RasterIO
    c:\vault\backroads\mapcanvas.cpp (324): CMapCanvas::LoadMap

  Data:
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........

    .... Continues on for a long time....

    FF FF FF FF    FF FF FF FF    FF FF FF FF    FF FF FF FF     ........
........
    FF FF FF FF                                                  ........
........

> -----Original Message-----
> From: fwarmerdam at gmail.com [mailto:fwarmerdam at gmail.com] On 
> Behalf Of Frank Warmerdam
> Sent: Thursday, December 14, 2006 10:50 PM
> To: Craig Miller
> Cc: Gdal-Dev
> Subject: Re: [Gdal-dev] Memory leak? How to release GDAL datasets?
> 
> On 12/13/06, Craig Miller <craig.miller at spatialminds.com> wrote:
> > Is GDALClose(m_pDataset) the only method that needs to be 
> called after 
> > opening a GDAL datset?
> 
> Craig,
> 
> That should be sufficient.
> 
> I really can't think why there would be any polygon geometry 
> creation going on to open a geotiff file.  I wonder if you 
> might be getting some sort of false report from your memory tester.
> 
> If you can point me to a file that demonstrates the problem, 
> I could try testing it under valgrind using something like gdalinfo.
> 
> 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