Skip to content
Permalink
Browse files
Fix leaked GDAL dataset handle when deleting layers
Prevents the deletion from actually occurring until QGIS is closed

(cherry picked from commit 842485f)
  • Loading branch information
nyalldawson committed Aug 17, 2021
1 parent 832945a commit ca6de5bf062991e4b985b3cae222fe5c79ab766e
Showing with 4 additions and 5 deletions.
  1. +4 −5 src/core/providers/ogr/qgsogrprovider.cpp
@@ -7073,16 +7073,16 @@ bool QgsOgrProviderUtils::deleteLayer( const QString &uri, QString &errCause )
openOptions );


GDALDatasetH hDS = GDALOpenEx( filePath.toUtf8().constData(), GDAL_OF_RASTER | GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr );
gdal::dataset_unique_ptr hDS( GDALOpenEx( filePath.toUtf8().constData(), GDAL_OF_RASTER | GDAL_OF_VECTOR | GDAL_OF_UPDATE, nullptr, nullptr, nullptr ) );
if ( hDS && ( ! layerName.isEmpty() || layerIndex != -1 ) )
{
// If we have got a name we convert it into an index
if ( ! layerName.isEmpty() )
{
layerIndex = -1;
for ( int i = 0; i < GDALDatasetGetLayerCount( hDS ); i++ )
for ( int i = 0; i < GDALDatasetGetLayerCount( hDS.get() ); i++ )
{
OGRLayerH hL = GDALDatasetGetLayer( hDS, i );
OGRLayerH hL = GDALDatasetGetLayer( hDS.get(), i );
if ( layerName == QString::fromUtf8( OGR_L_GetName( hL ) ) )
{
layerIndex = i;
@@ -7093,7 +7093,7 @@ bool QgsOgrProviderUtils::deleteLayer( const QString &uri, QString &errCause )
// Do delete!
if ( layerIndex != -1 )
{
OGRErr error = GDALDatasetDeleteLayer( hDS, layerIndex );
OGRErr error = GDALDatasetDeleteLayer( hDS.get(), layerIndex );
switch ( error )
{
case OGRERR_NOT_ENOUGH_DATA:
@@ -7123,7 +7123,6 @@ bool QgsOgrProviderUtils::deleteLayer( const QString &uri, QString &errCause )
case OGRERR_NON_EXISTING_FEATURE:
errCause = QObject::tr( "Non existing feature" );
break;
default:
case OGRERR_NONE:
errCause = QObject::tr( "Success" );
break;

0 comments on commit ca6de5b

Please sign in to comment.