Skip to content

Commit

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

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


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


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


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

0 comments on commit cd7592d

Please sign in to comment.