[gdal-dev] OGRRegisterAll memory leak
    Martin Chapman 
    mchapman at texelinc.com
       
    Sun Dec 30 23:01:08 EST 2007
    
    
  
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()
 
{
    CPLMutexHolderD( &hDRMutex );
    
    if( poRegistrar == NULL )
        poRegistrar = new OGRSFDriverRegistrar();
 
    return poRegistrar;
}
 
Where poRegistrar is being allocated and is suppose to be destroyed in:
 
void OGRCleanupAll()
 
{
    CPLMutexHolderD( &hDRMutex );
 
    if( poRegistrar != NULL )
        delete poRegistrar;
    OSRCleanup();
    CPLFinderClean();
    VSICleanupFileManager();
    CPLFreeConfig();
    CPLCleanupTLS();
}
 
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?
 
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);
 
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. 
 
Best regards,
 
Martin Chapman
Chief Software Architect
Fortified Datacom Inc.
http://www.fortifieddatacom.com
mchapman at fortifieddatacom.com
303-324-1065
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20071230/8f721bf5/attachment.html
    
    
More information about the gdal-dev
mailing list