1 | | GDALDestroyDriverManager() is called before OGRCleanupAll(), but the former does more thorough cleanup of CPL and GDAL resources. They should be called in reverse order. |
| 1 | 1. In supplied global destruction functions ''GDALDestroy'' and ''DllMain'' ''GDALDestroyDriverManager'' is called before ''OGRCleanupAll'' (http://trac.osgeo.org/gdal/browser/trunk/gdal/gcore/gdaldllmain.cpp#L80; http://trac.osgeo.org/gdal/browser/trunk/gdal/gcore/gdaldllmain.cpp#L119). |
| 2 | The former calls a bunch of cleanup functions ending with ''CPLCleanupMasterMutex'' (http://trac.osgeo.org/gdal/browser/trunk/gdal/gcore/gdaldrivermanager.cpp#L286). |
| 3 | Unfortunately, ''OGRCleanupAll'' immediately tries to get another mutex, recreating the master mutex (http://trac.osgeo.org/gdal/browser/trunk/gdal/ogr/ogrsf_frmts/generic/ogrsfdriverregistrar.cpp#L145). |
| 4 | |
| 5 | 2. There a is possibility that ''CPLCleanupMasterMutex'' will not be called at all, if ''GDALDriverManager'' is not instantiated (http://trac.osgeo.org/gdal/browser/trunk/gdal/gcore/gdaldrivermanager.cpp#L828). |
| 6 | |
| 7 | These issues can be fixed by adding required calls to ''OGRCleanupAll''. |