Skip to content
Permalink
Browse files

Avoid memory leak

  • Loading branch information
nyalldawson committed Jun 3, 2020
1 parent dbe2a9a commit d9dd2bf5735f69a6499482d066b2956ba5152d59
Showing with 8 additions and 1 deletion.
  1. +8 −1 src/analysis/processing/qgsalgorithmaggregate.cpp
@@ -141,6 +141,8 @@ QVariantMap QgsAggregateAlgorithm::processAlgorithm( const QVariantMap &paramete
QVector< QVariantList > keys; // We need deterministic order for the tests
QgsFeature feature;

std::vector< std::unique_ptr< QgsFeatureSink > > groupSinks;

QgsFeatureIterator it = mSource->getFeatures( QgsFeatureRequest() );
while ( it.nextFeature( feature ) )
{
@@ -170,7 +172,9 @@ QVariantMap QgsAggregateAlgorithm::processAlgorithm( const QVariantMap &paramete
QgsMapLayer *layer = QgsProcessingUtils::mapLayerFromString( id, context );

Group group;
group.sink = sink.release();
group.sink = sink.get();
//store ownership of sink in groupSinks, so that these get deleted automatically if an exception is raised later..
groupSinks.emplace_back( std::move( sink ) );
group.layer = layer;
group.feature = feature;
groups[key] = group;
@@ -187,6 +191,9 @@ QVariantMap QgsAggregateAlgorithm::processAlgorithm( const QVariantMap &paramete
break;
}

// early cleanup
groupSinks.clear();

QString destId;
std::unique_ptr< QgsFeatureSink > sink( parameterAsSink( parameters, QStringLiteral( "OUTPUT" ), context, destId, mFields, QgsWkbTypes::multiType( mSource->wkbType() ), mSource->sourceCrs() ) );
if ( !sink )

0 comments on commit d9dd2bf

Please sign in to comment.
You can’t perform that action at this time.