GDALDestroyDriverManager() - dataset cleanup
|Reported by:||Even Rouault||Owned by:||warmerdam|
Folks, I have modified GDALDriverManager::~GDALDriverManager() so that when it is destroyed it will first close all still-open GDAL datasets. A debug message will be issued for each dataset force-closed. This is part of an effort to ensure a clean shutdown and to make it easier to detect memory leaks in some situations. This is not a completely safe operation. In particular, if there are VRT files referencing other GDALDataset's the referenced dataset may be cleaned up before the referencing dataset which would be bad. I need this primarily for cleanup in MapServer where GDAL datasets are now normally left open (CLOSE_CONNECTION=DEFER). If this automatic dataset description causes problems we can disable or remove it before the GDAL 1.9 release. But it seems relatively harmless to incorporate in trunk for the time being. http://trac.osgeo.org/gdal/changeset/21662 Best regards,
This is indeed unsafe (a trivial code that opens a VRT and doesn't close it shows it under Valgrind), not only in VRT, but also for NITF (with JPEG compression), TIL, RS2, ERS and BIGGIF drivers (I established the list by finding the drivers that call GDALClose())
I have implemented a safer way by adding a new virtual method, GDALDataset::CloseDependantDatasets(), which is called by GDALDriverManager::~GDALDriverManager() on the list of still opened datasets while there are datasets that still declare dependant datasets. Once all remaining datasets are "stand-alone" they can safely be destroyed.