[mapserver-commits] r10785 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Tue Dec 7 23:28:36 EST 2010


Author: warmerdam
Date: 2010-12-07 20:28:36 -0800 (Tue, 07 Dec 2010)
New Revision: 10785

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapgdal.c
Log:
added logic to cleanup open datasets but only with very new GDALs

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2010-12-07 20:42:06 UTC (rev 10784)
+++ trunk/mapserver/HISTORY.TXT	2010-12-08 04:28:36 UTC (rev 10785)
@@ -13,6 +13,10 @@
 
 Current Version (SVN trunk):
 ----------------------------
+
+- Cleanup open gdal datasets in msGDALCleanup() (if we have a very new
+  GDAL).  This makes it easier to identify memory leaks. 
+
 - Add support for per layer tuning of the shape to pixel conversion (SIMPLIFY, ROUND,
   SNAPTOGRID, FULLRESOLUTION)
 

Modified: trunk/mapserver/mapgdal.c
===================================================================
--- trunk/mapserver/mapgdal.c	2010-12-07 20:42:06 UTC (rev 10784)
+++ trunk/mapserver/mapgdal.c	2010-12-08 04:28:36 UTC (rev 10785)
@@ -71,9 +71,39 @@
     if( bGDALInitialized )
     {
         int iRepeat = 5;
-
         msAcquireLock( TLOCK_GDAL );
 
+#if GDAL_RELEASE_DATE > 20101207
+        {
+            /* 
+            ** Cleanup any unreferenced but open datasets as will tend
+            ** to exist due to deferred close requests.  We are careful
+            ** to only close one file at a time before refecting the
+            ** list as closing some datasets may cause others to be 
+            ** closed (subdatasets in a VRT for instance).
+            */
+            GDALDatasetH *pahDSList = NULL;
+            int nDSCount = 0;
+            int bDidSomething;
+
+            do {
+                int i;
+                GDALGetOpenDatasets( &pahDSList, &nDSCount );
+                bDidSomething = FALSE;
+                for( i = 0; i < nDSCount && !bDidSomething; i++ )
+                {
+                    if( GDALReferenceDataset( pahDSList[i] ) == 1 )
+                    {
+                        GDALClose( pahDSList[i] );
+                        bDidSomething = TRUE;
+                    }
+                    else
+                        GDALDereferenceDataset( pahDSList[i] );
+                }
+            } while( bDidSomething );
+        }
+#endif
+
         while( iRepeat-- )
             CPLPopErrorHandler();
 



More information about the mapserver-commits mailing list