Navigation Menu

Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 24, 2021
1 parent ff17205 commit 4016205
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/core/expression/qgsexpressionfunction.cpp
Expand Up @@ -1359,26 +1359,26 @@ static QVariant fcnLength( const QVariantList &values, const QgsExpressionContex

static QVariant fcnLength3D( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
{
QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
const QgsGeometry geom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );

if ( geom.type() != QgsWkbTypes::LineGeometry )
return QVariant();

if ( !geom.isMultipart() )
return QVariant( qgsgeometry_cast< const QgsCurve * >( geom.constGet() )->curveToLine()->length3D() );

if ( const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection * >( geom.constGet() ) )
double totalLength = 0;
for ( auto it = geom.const_parts_begin(); it != geom.const_parts_end(); ++it )
{
double sumLength3DParts = 0;
for ( int i = 0; i < collection->numGeometries(); ++i )
if ( const QgsLineString *line = qgsgeometry_cast< const QgsLineString * >( *it ) )
{
if ( const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( collection->geometryN( i ) ) )
sumLength3DParts += curve->curveToLine()->length3D();
totalLength += line->length3D();
}
else
{
std::unique_ptr< QgsLineString > segmentized( qgsgeometry_cast< const QgsCurve * >( *it )->curveToLine() );
totalLength += segmentized->length3D();
}
return QVariant( sumLength3DParts );
}

return QVariant();
return totalLength;
}

static QVariant fcnReplace( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
Expand Down

0 comments on commit 4016205

Please sign in to comment.