Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix memory leaks in geometry expression functions
(cherry-picked from cd7592d)
  • Loading branch information
nyalldawson committed Aug 15, 2015
1 parent c7b1080 commit 7687204
Showing 1 changed file with 30 additions and 38 deletions.
68 changes: 30 additions & 38 deletions src/core/qgsexpression.cpp
Expand Up @@ -1095,20 +1095,17 @@ static QVariant fcnGeomFromWKT( const QVariantList& values, const QgsFeature*, Q
{
QString wkt = getStringValue( values.at( 0 ), parent );
QgsGeometry* geom = QgsGeometry::fromWkt( wkt );
if ( geom )
return QVariant::fromValue( *geom );
else
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnGeomFromGML( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
QString gml = getStringValue( values.at( 0 ), parent );
QgsGeometry* geom = QgsOgcUtils::geometryFromGML( gml );

if ( geom )
return QVariant::fromValue( *geom );
else
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}

static QVariant fcnGeomArea( const QVariantList&, const QgsFeature* f, QgsExpression* parent )
Expand All @@ -1134,14 +1131,9 @@ static QVariant fcnBounds( const QVariantList& values, const QgsFeature*, QgsExp
{
QgsGeometry geom = getGeometry( values.at( 0 ), parent );
QgsGeometry* geomBounds = QgsGeometry::fromRect( geom.boundingBox() );
if ( geomBounds )
{
return QVariant::fromValue( *geomBounds );
}
else
{
return QVariant();
}
QVariant result = geomBounds ? QVariant::fromValue( *geomBounds ) : QVariant();
delete geomBounds;
return result;
}

static QVariant fcnBoundsWidth( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
Expand Down Expand Up @@ -1240,34 +1232,34 @@ static QVariant fcnBuffer( const QVariantList& values, const QgsFeature*, QgsExp
seg = getIntValue( values.at( 2 ), parent );

QgsGeometry* geom = fGeom.buffer( dist, seg );
if ( geom )
return QVariant::fromValue( *geom );
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnCentroid( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
QgsGeometry fGeom = getGeometry( values.at( 0 ), parent );
QgsGeometry* geom = fGeom.centroid();
if ( geom )
return QVariant::fromValue( *geom );
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnConvexHull( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
QgsGeometry fGeom = getGeometry( values.at( 0 ), parent );
QgsGeometry* geom = fGeom.convexHull();
if ( geom )
return QVariant::fromValue( *geom );
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnDifference( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
QgsGeometry fGeom = getGeometry( values.at( 0 ), parent );
QgsGeometry sGeom = getGeometry( values.at( 1 ), parent );
QgsGeometry* geom = fGeom.difference( &sGeom );
if ( geom )
return QVariant::fromValue( *geom );
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnDistance( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
Expand All @@ -1280,27 +1272,27 @@ static QVariant fcnIntersection( const QVariantList& values, const QgsFeature*,
QgsGeometry fGeom = getGeometry( values.at( 0 ), parent );
QgsGeometry sGeom = getGeometry( values.at( 1 ), parent );
QgsGeometry* geom = fGeom.intersection( &sGeom );
if ( geom )
return QVariant::fromValue( *geom );
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnSymDifference( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
QgsGeometry fGeom = getGeometry( values.at( 0 ), parent );
QgsGeometry sGeom = getGeometry( values.at( 1 ), parent );
QgsGeometry* geom = fGeom.symDifference( &sGeom );
if ( geom )
return QVariant::fromValue( *geom );
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnCombine( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
QgsGeometry fGeom = getGeometry( values.at( 0 ), parent );
QgsGeometry sGeom = getGeometry( values.at( 1 ), parent );
QgsGeometry* geom = fGeom.combine( &sGeom );
if ( geom )
return QVariant::fromValue( *geom );
return QVariant();
QVariant result = geom ? QVariant::fromValue( *geom ) : QVariant();
delete geom;
return result;
}
static QVariant fcnGeomToWKT( const QVariantList& values, const QgsFeature*, QgsExpression* parent )
{
Expand Down

0 comments on commit 7687204

Please sign in to comment.