Skip to content

Commit

Permalink
Inverted polygons: fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Mercier committed Jun 16, 2014
1 parent b2782ee commit 71a1f89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6402,16 +6402,18 @@ namespace QgsGeometryAlgorithms

QgsGeometry* unaryUnion( const QList<QgsGeometry*>& geometryList )
{
QList<GEOSGeometry*> geoms;
QVector<GEOSGeometry*> geoms;
foreach( QgsGeometry* g, geometryList )
{
// const cast: it is ok here, since the pointers will only be used to be stored
// in a list for a call to union
geoms.append( const_cast<GEOSGeometry*>(g->asGeos()) );
geoms.append( GEOSGeom_clone(g->asGeos()) );
}
GEOSGeometry* unioned = _makeUnion( geoms );

GEOSGeometry* geomCollection = 0;
geomCollection = createGeosCollection( GEOS_GEOMETRYCOLLECTION, geoms );
GEOSGeometry* geomUnion = GEOSUnaryUnion( geomCollection );
GEOSGeom_destroy( geomCollection );
QgsGeometry *ret = new QgsGeometry();
ret->fromGeos( unioned );
ret->fromGeos( geomUnion );
return ret;
}

Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void QgsInvertedPolygonRenderer::startRender( QgsRenderContext& context, const Q
mSubRenderer->startRender( context, fields );

mFeaturesCategories.clear();
mSymbolCategories.clear();
mFeatureDecorations.clear();
mFields = fields;

Expand Down Expand Up @@ -279,6 +280,13 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
}
mSubRenderer->renderFeature( feat, mContext );
}
for ( FeatureCategoryVector::iterator cit = mFeaturesCategories.begin(); cit != mFeaturesCategories.end(); ++cit )
{
foreach( QgsGeometry* g, cit->geometries )
{
delete g;
}
}

// when no features are visible, we still have to draw the exterior rectangle
// warning: when sub renderers have more than one possible symbols,
Expand Down

0 comments on commit 71a1f89

Please sign in to comment.