[gdal-dev] OGRRegisterAll memory leak

Frank Warmerdam warmerdam at pobox.com
Mon Dec 31 09:16:29 EST 2007


Martin Chapman wrote:
> I have a concern about OGRSFDriverRegistrar.  It appears that when I 
> call OGRRegisterAll()  the following function is called:
> 
> OGRSFDriverRegistrar::GetRegistrar()->AutoLoadDrivers();
> 
> That calls:
> 
> OGRSFDriverRegistrar *OGRSFDriverRegistrar::GetRegistrar()
...
> Where poRegistrar is being allocated and is suppose to be destroyed in:
> 
> void OGRCleanupAll()
...
> But that function (OGRCleanupAll) never gets called when my application 
> closes.  Question: Am I suppose to be calling some method to deallocate 
> objects allocated in the call to OGRRegisterAll() or is this a bug in 
> GetRegistrar() or AutoLoadDrivers()?  Should OGRCleanupAll() be called 
> in that function?

Martin,

This is the expected operation.

> I found OGRCleanupAll() declared in ogr_api.h with the following 
> comments but OGRCleanupAll() is not declared in ogrsf_frmts.h as indicated.
> 
> /* note: this is also declared in ogrsf_frmts.h */
> 
> void CPL_DLL OGRRegisterAll(void);
> 
> void CPL_DLL OGRCleanupAll(void);

The comment about also being declared in ogrsf_frmts.h appears to only
apply to the OGRRegisterAll().

> When I inlcude ogr_api,h and call OGRCleanupAll() in my desctructor then 
> all the memory leaks go away and since OGRCleanupAll() is not being 
> called anywhere else and as far as I can tell from the website is 
> undocumented which can easily lead to user created memory leaks.  
> Thought you guys would like to know that. Please correct me if I am 
> missing something.

Note that the memory leaks are "one time" leaks for the singleton
registrar.  Multiple calls to OGRRegisterAll() will not increase the
memory used.  OGRCleanupAll() is mainly intended for use when developers
wish to do memory leak testing, and want to clean away all known
"one time" allocations on exit.

I have added improved documentation on OGRSFDriverRegistrar and
OGRCleanupAll() in trunk that will hopefully make this somewhat
clearer for folks in the future.

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    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list