Skip to content

Commit e5fb5a6

Browse files
committed
Fix memory leaks
1 parent 39f4ed5 commit e5fb5a6

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/plugins/topology/topolTest.cpp

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -416,21 +416,21 @@ ErrorList topolTest::checkDuplicates( double tolerance, QgsVectorLayer *layer1,
416416

417417
QList<FeatureLayer> fls;
418418
fls << *it << *it;
419-
QgsGeometry* conflict = new QgsGeometry( *g1 );
419+
QScopedPointer<QgsGeometry> conflict( new QgsGeometry( *g1 ) );
420420

421421
if ( isExtent )
422422
{
423-
if ( canvasExtentPoly->disjoint( conflict ) )
423+
if ( canvasExtentPoly->disjoint( conflict.data() ) )
424424
{
425425
continue;
426426
}
427-
if ( canvasExtentPoly->crosses( conflict ) )
427+
if ( canvasExtentPoly->crosses( conflict.data() ) )
428428
{
429-
conflict = conflict->intersection( canvasExtentPoly );
429+
conflict.reset( conflict->intersection( canvasExtentPoly ) );
430430
}
431431
}
432432

433-
TopolErrorDuplicates* err = new TopolErrorDuplicates( bb, conflict, fls );
433+
TopolErrorDuplicates* err = new TopolErrorDuplicates( bb, conflict.take(), fls );
434434

435435
errorList << err;
436436
}
@@ -543,21 +543,21 @@ ErrorList topolTest::checkOverlaps( double tolerance, QgsVectorLayer *layer1, Qg
543543
{
544544
QList<FeatureLayer> fls;
545545
fls << *it << *it;
546-
QgsGeometry* conflictGeom = g1->intersection( g2 );
546+
QScopedPointer< QgsGeometry > conflictGeom( g1->intersection( g2 ) );
547547

548548
if ( isExtent )
549549
{
550-
if ( canvasExtentPoly->disjoint( conflictGeom ) )
550+
if ( canvasExtentPoly->disjoint( conflictGeom.data() ) )
551551
{
552552
continue;
553553
}
554-
if ( canvasExtentPoly->crosses( conflictGeom ) )
554+
if ( canvasExtentPoly->crosses( conflictGeom.data() ) )
555555
{
556-
conflictGeom = conflictGeom->intersection( canvasExtentPoly );
556+
conflictGeom.reset( conflictGeom->intersection( canvasExtentPoly ) );
557557
}
558558
}
559559

560-
TopolErrorOverlaps* err = new TopolErrorOverlaps( bb, conflictGeom, fls );
560+
TopolErrorOverlaps* err = new TopolErrorOverlaps( bb, conflictGeom.take(), fls );
561561

562562
errorList << err;
563563
}
@@ -637,6 +637,7 @@ ErrorList topolTest::checkGaps( double tolerance, QgsVectorLayer *layer1, QgsVec
637637
QgsGeometry* polyGeom = QgsGeometry::fromPolygon( polygon );
638638

639639
geomList.push_back( GEOSGeom_clone_r( geosctxt, polyGeom->asGeos() ) );
640+
delete polyGeom;
640641
}
641642

642643
}
@@ -954,6 +955,7 @@ ErrorList topolTest::checkPointCoveredBySegment( double tolerance, QgsVectorLaye
954955
{
955956
if ( canvasExtentPoly->disjoint( conflictGeom ) )
956957
{
958+
delete conflictGeom;
957959
continue;
958960
}
959961
}
@@ -1178,7 +1180,7 @@ ErrorList topolTest::checkOverlapWithLayer( double tolerance, QgsVectorLayer* la
11781180
QgsRectangle r2 = g2->boundingBox();
11791181
r.combineExtentWith( &r2 );
11801182

1181-
QgsGeometry* conflictGeom = g1->intersection( g2 );
1183+
QScopedPointer<QgsGeometry> conflictGeom( g1->intersection( g2 ) );
11821184
// could this for some reason return NULL?
11831185
if ( !conflictGeom )
11841186
{
@@ -1187,13 +1189,13 @@ ErrorList topolTest::checkOverlapWithLayer( double tolerance, QgsVectorLayer* la
11871189

11881190
if ( isExtent )
11891191
{
1190-
if ( canvasExtentPoly->disjoint( conflictGeom ) )
1192+
if ( canvasExtentPoly->disjoint( conflictGeom.data() ) )
11911193
{
11921194
continue;
11931195
}
1194-
if ( canvasExtentPoly->crosses( conflictGeom ) )
1196+
if ( canvasExtentPoly->crosses( conflictGeom.data() ) )
11951197
{
1196-
conflictGeom = conflictGeom->intersection( canvasExtentPoly );
1198+
conflictGeom.reset( conflictGeom->intersection( canvasExtentPoly ) );
11971199
}
11981200
}
11991201

@@ -1204,7 +1206,7 @@ ErrorList topolTest::checkOverlapWithLayer( double tolerance, QgsVectorLayer* la
12041206
fl.feature = f;
12051207
fl.layer = layer2;
12061208
fls << *it << fl;
1207-
TopolErrorIntersection* err = new TopolErrorIntersection( r, conflictGeom, fls );
1209+
TopolErrorIntersection* err = new TopolErrorIntersection( r, conflictGeom.take(), fls );
12081210

12091211
errorList << err;
12101212
}
@@ -1279,6 +1281,7 @@ ErrorList topolTest::checkPointCoveredByLineEnds( double tolerance, QgsVectorLay
12791281
{
12801282
if ( canvasExtentPoly->disjoint( conflictGeom ) )
12811283
{
1284+
delete conflictGeom;
12821285
continue;
12831286
}
12841287
}
@@ -1372,25 +1375,24 @@ ErrorList topolTest::checkyLineEndsCoveredByPoints( double tolerance, QgsVectorL
13721375

13731376
if ( !touched )
13741377
{
1375-
QgsGeometry* conflictGeom = new QgsGeometry( *g1 );
1378+
QScopedPointer<QgsGeometry> conflictGeom( new QgsGeometry( *g1 ) );
13761379

13771380
if ( isExtent )
13781381
{
1379-
if ( canvasExtentPoly->disjoint( conflictGeom ) )
1382+
if ( canvasExtentPoly->disjoint( conflictGeom.data() ) )
13801383
{
13811384
continue;
13821385
}
1383-
if ( canvasExtentPoly->crosses( conflictGeom ) )
1386+
if ( canvasExtentPoly->crosses( conflictGeom.data() ) )
13841387
{
1385-
conflictGeom = conflictGeom->intersection( canvasExtentPoly );
1388+
conflictGeom.reset( conflictGeom->intersection( canvasExtentPoly ) );
13861389
}
13871390
}
13881391
QList<FeatureLayer> fls;
13891392
fls << *it << *it;
13901393
//bb.scale(10);
13911394

1392-
1393-
TopolErrorLineEndsNotCoveredByPoints* err = new TopolErrorLineEndsNotCoveredByPoints( bb, conflictGeom, fls );
1395+
TopolErrorLineEndsNotCoveredByPoints* err = new TopolErrorLineEndsNotCoveredByPoints( bb, conflictGeom.take(), fls );
13941396
errorList << err;
13951397
}
13961398
}
@@ -1456,6 +1458,7 @@ ErrorList topolTest::checkPointInPolygon( double tolerance, QgsVectorLayer *laye
14561458
{
14571459
if ( canvasExtentPoly->disjoint( conflictGeom ) )
14581460
{
1461+
delete conflictGeom;
14591462
continue;
14601463
}
14611464
}

0 commit comments

Comments
 (0)