Skip to content

Commit

Permalink
Avoid memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 3, 2020
1 parent dbe2a9a commit d9dd2bf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/analysis/processing/qgsalgorithmaggregate.cpp
Expand Up @@ -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 ) )
{
Expand Down Expand Up @@ -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;
Expand All @@ -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 )
Expand Down

0 comments on commit d9dd2bf

Please sign in to comment.