Skip to content

Commit

Permalink
Merge pull request #44449 from nyalldawson/backport_44392
Browse files Browse the repository at this point in the history
Fix leaked GDAL dataset handle when deleting layers (3.20)
  • Loading branch information
elpaso committed Jul 30, 2021
2 parents 90b8636 + 840485f commit 655862f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -7580,16 +7580,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;
Expand All @@ -7600,7 +7600,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:
Expand Down Expand Up @@ -7630,7 +7630,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;
Expand Down

0 comments on commit 655862f

Please sign in to comment.