Fix leak in geos::linePointDifference

This commit is contained in:
Nyall Dawson 2023-09-14 16:31:39 +10:00
parent bf45674bc2
commit dc719fbbb7

View File

@ -1021,17 +1021,22 @@ geos::unique_ptr QgsGeos::linePointDifference( GEOSGeometry *GEOSsplitPoint ) co
// we might have a point or a multipoint, depending on number of // we might have a point or a multipoint, depending on number of
// intersections between the geometry and the split geometry // intersections between the geometry and the split geometry
std::unique_ptr< QgsAbstractGeometry > splitGeom( fromGeos( GEOSsplitPoint ) ); std::unique_ptr< QgsMultiPoint > splitPoints;
std::unique_ptr< QgsMultiPoint > splitPoints( qgsgeometry_cast<QgsMultiPoint *>( splitGeom->clone() ) );
if ( !splitPoints )
{ {
QgsPoint *splitPoint = qgsgeometry_cast<QgsPoint *>( splitGeom->clone() ); std::unique_ptr< QgsAbstractGeometry > splitGeom( fromGeos( GEOSsplitPoint ) );
if ( !splitPoint )
if ( qgsgeometry_cast<QgsMultiPoint *>( splitGeom.get() ) )
{ {
return nullptr; splitPoints.reset( qgsgeometry_cast<QgsMultiPoint *>( splitGeom.release() ) );
}
else if ( qgsgeometry_cast<QgsPoint *>( splitGeom.get() ) )
{
splitPoints = std::make_unique< QgsMultiPoint >();
if ( QgsPoint *point = qgsgeometry_cast<QgsPoint *>( splitGeom.get() ) )
{
splitPoints->addGeometry( qgsgeometry_cast<QgsPoint *>( splitGeom.release() ) );
}
} }
splitPoints.reset( new QgsMultiPoint() );
splitPoints->addGeometry( splitPoint );
} }
QgsMultiCurve lines; QgsMultiCurve lines;