Skip to content

Commit

Permalink
Fix memory leak in geometry snapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 7, 2017
1 parent cb1849f commit c400326
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/analysis/vector/qgsgeometrysnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,12 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry& geometry, doubl
return QgsGeometry( subjGeom );

// SnapIndex for subject feature
QgsSnapIndex* subjSnapIndex = new QgsSnapIndex( center, 10 * snapTolerance );
std::unique_ptr< QgsSnapIndex > subjSnapIndex( new QgsSnapIndex( center, 10 * snapTolerance ) );
subjSnapIndex->addGeometry( subjGeom );

QgsAbstractGeometry* origSubjGeom = subjGeom->clone();
QgsSnapIndex* origSubjSnapIndex = new QgsSnapIndex( center, 10 * snapTolerance );
origSubjSnapIndex->addGeometry( origSubjGeom );
std::unique_ptr< QgsAbstractGeometry > origSubjGeom( subjGeom->clone() );
std::unique_ptr< QgsSnapIndex > origSubjSnapIndex( new QgsSnapIndex( center, 10 * snapTolerance ) );
origSubjSnapIndex->addGeometry( origSubjGeom.get() );

// Pass 2: add missing vertices to subject geometry
Q_FOREACH ( const QgsGeometry& refGeom, refGeometries )
Expand Down Expand Up @@ -638,17 +638,17 @@ QgsGeometry QgsGeometrySnapper::snapGeometry( const QgsGeometry& geometry, doubl
const QgsSnapIndex::CoordIdx* idx = snapSegment->idxFrom;
subjGeom->insertVertex( QgsVertexId( idx->vidx.part, idx->vidx.ring, idx->vidx.vertex + 1 ), point );
subjPointFlags[idx->vidx.part][idx->vidx.ring].insert( idx->vidx.vertex + 1, SnappedToRefNode );
delete subjSnapIndex;
subjSnapIndex = new QgsSnapIndex( center, 10 * snapTolerance );
subjSnapIndex.reset( new QgsSnapIndex( center, 10 * snapTolerance ) );
subjSnapIndex->addGeometry( subjGeom );
}
}
}
}
}
}
delete subjSnapIndex;
delete origSubjSnapIndex;
subjSnapIndex.reset();
origSubjSnapIndex.reset();
origSubjGeom.reset();

// Pass 3: remove superfluous vertices: all vertices which are snapped to a segment and not preceded or succeeded by an unsnapped vertex
for ( int iPart = 0, nParts = subjGeom->partCount(); iPart < nParts; ++iPart )
Expand Down

0 comments on commit c400326

Please sign in to comment.