Skip to content
Permalink
Browse files

Fix some memory leaks

  • Loading branch information
nyalldawson committed Nov 23, 2017
1 parent 1178428 commit c04b91f4f315f8ddf5a8699647ec96820dc01e17
@@ -517,7 +517,7 @@ QgsGeometry QgsInternalGeometryEngine::orthogonalize( double tolerance, int maxI
}

// if extraNodesPerSegment < 0, then use distance based mode
QgsLineString *doDensify( QgsLineString *ring, int extraNodesPerSegment = -1, double distance = 1 )
QgsLineString *doDensify( const QgsLineString *ring, int extraNodesPerSegment = -1, double distance = 1 )
{
QVector< double > outX;
QVector< double > outY;
@@ -627,11 +627,11 @@ QgsAbstractGeometry *densifyGeometry( const QgsAbstractGeometry *geom, int extra
const QgsPolygon *polygon = static_cast< const QgsPolygon * >( geom );
QgsPolygon *result = new QgsPolygon();

result->setExteriorRing( doDensify( static_cast< QgsLineString * >( polygon->exteriorRing()->clone() ),
result->setExteriorRing( doDensify( static_cast< const QgsLineString * >( polygon->exteriorRing() ),
extraNodesPerSegment, distance ) );
for ( int i = 0; i < polygon->numInteriorRings(); ++i )
{
result->addInteriorRing( doDensify( static_cast< QgsLineString * >( polygon->interiorRing( i )->clone() ),
result->addInteriorRing( doDensify( static_cast< const QgsLineString * >( polygon->interiorRing( i ) ),
extraNodesPerSegment, distance ) );
}

@@ -183,7 +183,7 @@ bool QgsProcessingAlgorithm::validateInputCrs( const QVariantMap &parameters, Qg
}
else if ( def->type() == QStringLiteral( "source" ) )
{
QgsFeatureSource *source = QgsProcessingParameters::parameterAsSource( def, parameters, context );
std::unique_ptr< QgsFeatureSource > source( QgsProcessingParameters::parameterAsSource( def, parameters, context ) );
if ( source )
{
if ( foundCrs && source->sourceCrs().isValid() && crs != source->sourceCrs() )
@@ -787,15 +787,15 @@ void TestQgsProcessing::mapLayers()

// Test layers from a string with parameters
QString osmFilePath = testDataDir + "openstreetmap/testdata.xml";
QgsVectorLayer *osm = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath ) );
std::unique_ptr< QgsVectorLayer > osm( qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath ) ) );
QVERIFY( osm->isValid() );
QCOMPARE( osm->geometryType(), QgsWkbTypes::PointGeometry );

osm = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath + "|layerid=3" ) );
osm.reset( qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath + "|layerid=3" ) ) );
QVERIFY( osm->isValid() );
QCOMPARE( osm->geometryType(), QgsWkbTypes::PolygonGeometry );

osm = qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath + "|layerid=3|subset=\"building\" is not null" ) );
osm.reset( qobject_cast< QgsVectorLayer *>( QgsProcessingUtils::loadMapLayerFromString( osmFilePath + "|layerid=3|subset=\"building\" is not null" ) ) );
QVERIFY( osm->isValid() );
QCOMPARE( osm->geometryType(), QgsWkbTypes::PolygonGeometry );
QCOMPARE( osm->subsetString(), QStringLiteral( "\"building\" is not null" ) );
@@ -966,6 +966,7 @@ void TestQgsProcessing::algorithm()
QVERIFY( p2->algorithms().isEmpty() );
p2->load();
QCOMPARE( p2->algorithms().size(), 2 );
delete p2;

// test that adding a provider to the registry automatically refreshes algorithms (via load)
DummyProvider *p3 = new DummyProvider( "p3" );
@@ -4471,24 +4472,24 @@ void TestQgsProcessing::combineLayerExtent()
QString raster1 = testDataDir + "tenbytenraster.asc";
QString raster2 = testDataDir + "landsat.tif";
QFileInfo fi1( raster1 );
QgsRasterLayer *r1 = new QgsRasterLayer( fi1.filePath(), "R1" );
std::unique_ptr< QgsRasterLayer > r1( new QgsRasterLayer( fi1.filePath(), "R1" ) );
QFileInfo fi2( raster2 );
QgsRasterLayer *r2 = new QgsRasterLayer( fi2.filePath(), "R2" );
std::unique_ptr< QgsRasterLayer > r2( new QgsRasterLayer( fi2.filePath(), "R2" ) );

ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1 );
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() );
QGSCOMPARENEAR( ext.xMinimum(), 1535375.000000, 10 );
QGSCOMPARENEAR( ext.xMaximum(), 1535475, 10 );
QGSCOMPARENEAR( ext.yMinimum(), 5083255, 10 );
QGSCOMPARENEAR( ext.yMaximum(), 5083355, 10 );

ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1 << r2 );
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() << r2.get() );
QGSCOMPARENEAR( ext.xMinimum(), 781662, 10 );
QGSCOMPARENEAR( ext.xMaximum(), 1535475, 10 );
QGSCOMPARENEAR( ext.yMinimum(), 3339523, 10 );
QGSCOMPARENEAR( ext.yMaximum(), 5083355, 10 );

// with reprojection
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1 << r2, QgsCoordinateReferenceSystem::fromEpsgId( 3785 ) );
ext = QgsProcessingUtils::combineLayerExtents( QList< QgsMapLayer *>() << r1.get() << r2.get(), QgsCoordinateReferenceSystem::fromEpsgId( 3785 ) );
QGSCOMPARENEAR( ext.xMinimum(), 1995320, 10 );
QGSCOMPARENEAR( ext.xMaximum(), 2008833, 10 );
QGSCOMPARENEAR( ext.yMinimum(), 3523084, 10 );
@@ -5697,7 +5698,7 @@ void TestQgsProcessing::convertCompatible()
QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) );

// make sure all features are copied
QgsVectorLayer *t = new QgsVectorLayer( out, "vl2" );
std::unique_ptr< QgsVectorLayer > t = qgis::make_unique< QgsVectorLayer >( out, "vl2" );
QCOMPARE( layer->featureCount(), t->featureCount() );
QCOMPARE( layer->crs(), t->crs() );

@@ -5715,17 +5716,15 @@ void TestQgsProcessing::convertCompatible()
QVERIFY( out != layer->source() );
QVERIFY( out.endsWith( ".tab" ) );
QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) );
delete t;
t = new QgsVectorLayer( out, "vl2" );
t = qgis::make_unique< QgsVectorLayer >( out, "vl2" );
QCOMPARE( t->featureCount(), static_cast< long >( ids.count() ) );

// using a selection but existing format - will still require translation
out = QgsProcessingUtils::convertToCompatibleFormat( layer, true, QStringLiteral( "test" ), QStringList() << "shp", QString( "shp" ), context, &feedback );
QVERIFY( out != layer->source() );
QVERIFY( out.endsWith( ".shp" ) );
QVERIFY( out.startsWith( QgsProcessingUtils::tempFolder() ) );
delete t;
t = new QgsVectorLayer( out, "vl2" );
t = qgis::make_unique< QgsVectorLayer >( out, "vl2" );
QCOMPARE( t->featureCount(), static_cast< long >( ids.count() ) );


0 comments on commit c04b91f

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