Skip to content

Commit 22f5ba2

Browse files
committed
Close gdal/ogr data sources when finished in dataItems implementation
1 parent 42418b1 commit 22f5ba2

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/providers/gdal/qgsgdalprovider.cpp

+17-15
Original file line numberDiff line numberDiff line change
@@ -884,12 +884,12 @@ void QgsGdalProvider::computeMinMax( int theBandNo )
884884
return;
885885
}
886886
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
887-
int bApproxOK=false;
887+
int bApproxOK = false;
888888
int bGotMin, bGotMax;
889889
double adfMinMax[2];
890890
adfMinMax[0] = GDALGetRasterMinimum( myGdalBand, &bGotMin );
891891
adfMinMax[1] = GDALGetRasterMaximum( myGdalBand, &bGotMax );
892-
if( ! ( bGotMin && bGotMax ) )
892+
if ( !( bGotMin && bGotMax ) )
893893
{
894894
GDALComputeRasterMinMax( myGdalBand, TRUE, adfMinMax );
895895
}
@@ -1838,7 +1838,7 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo )
18381838
{
18391839
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo );
18401840
QgsRasterBandStats myRasterBandStats;
1841-
int bApproxOK=false;
1841+
int bApproxOK = false;
18421842
double pdfMin;
18431843
double pdfMax;
18441844
double pdfMean;
@@ -1847,26 +1847,26 @@ QgsRasterBandStats QgsGdalProvider::bandStatistics( int theBandNo )
18471847
myProg.type = ProgressHistogram;
18481848
myProg.provider = this;
18491849

1850-
// double myerval =
1851-
// GDALComputeRasterStatistics (
1852-
// myGdalBand, bApproxOK, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
1853-
// progressCallback, &myProg ) ;
1854-
// double myerval =
1850+
// double myerval =
1851+
// GDALComputeRasterStatistics (
1852+
// myGdalBand, bApproxOK, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
1853+
// progressCallback, &myProg ) ;
1854+
// double myerval =
18551855
// GDALGetRasterStatistics ( myGdalBand, bApproxOK, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev);
1856-
// double myerval =
1856+
// double myerval =
18571857
// GDALGetRasterStatisticsProgress ( myGdalBand, bApproxOK, TRUE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
1858-
// progressCallback, &myProg );
1858+
// progressCallback, &myProg );
18591859

18601860
// try to fetch the cached stats (bForce=FALSE)
1861-
CPLErr myerval =
1862-
GDALGetRasterStatistics ( myGdalBand, bApproxOK, FALSE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev);
1861+
CPLErr myerval =
1862+
GDALGetRasterStatistics( myGdalBand, bApproxOK, FALSE, &pdfMin, &pdfMax, &pdfMean, &pdfStdDev );
18631863

18641864
// if cached stats are not found, compute them
18651865
if ( CE_Warning == myerval )
18661866
{
1867-
myerval = GDALComputeRasterStatistics ( myGdalBand, bApproxOK,
1868-
&pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
1869-
progressCallback, &myProg ) ;
1867+
myerval = GDALComputeRasterStatistics( myGdalBand, bApproxOK,
1868+
&pdfMin, &pdfMax, &pdfMean, &pdfStdDev,
1869+
progressCallback, &myProg ) ;
18701870
}
18711871

18721872
// if stats are found populate the QgsRasterBandStats object
@@ -2010,6 +2010,8 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
20102010
if ( !hDS )
20112011
return 0;
20122012

2013+
GDALClose( hDS );
2014+
20132015
QgsDebugMsg( "GdalDataset opened " + thePath );
20142016

20152017
QString name = info.fileName();

src/providers/ogr/qgsogrprovider.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -2288,7 +2288,10 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
22882288
int numLayers = OGR_DS_GetLayerCount( hDataSource );
22892289

22902290
if ( numLayers == 0 )
2291+
{
2292+
OGR_DS_Destroy( hDataSource );
22912293
return 0;
2294+
}
22922295

22932296
QgsDataCollectionItem * collection = 0;
22942297
if ( numLayers > 1 )
@@ -2352,10 +2355,14 @@ QGISEXTERN QgsDataItem * dataItem( QString thePath, QgsDataItem* parentItem )
23522355

23532356
QgsOgrLayerItem * item = new QgsOgrLayerItem( collection ? collection : parentItem, name, path, layerUri, layerType );
23542357
if ( numLayers == 1 )
2358+
{
2359+
OGR_DS_Destroy( hDataSource );
23552360
return item;
2361+
}
23562362
collection->addChild( item );
23572363
}
23582364
collection->setPopulated();
2365+
OGR_DS_Destroy( hDataSource );
23592366
return collection;
23602367
}
23612368

0 commit comments

Comments
 (0)