Skip to content

Commit 71a1f89

Browse files
author
Hugo Mercier
committed
Inverted polygons: fix memory leaks
1 parent b2782ee commit 71a1f89

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/core/qgsgeometry.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6402,16 +6402,18 @@ namespace QgsGeometryAlgorithms
64026402

64036403
QgsGeometry* unaryUnion( const QList<QgsGeometry*>& geometryList )
64046404
{
6405-
QList<GEOSGeometry*> geoms;
6405+
QVector<GEOSGeometry*> geoms;
64066406
foreach( QgsGeometry* g, geometryList )
64076407
{
6408-
// const cast: it is ok here, since the pointers will only be used to be stored
6409-
// in a list for a call to union
6410-
geoms.append( const_cast<GEOSGeometry*>(g->asGeos()) );
6408+
geoms.append( GEOSGeom_clone(g->asGeos()) );
64116409
}
6412-
GEOSGeometry* unioned = _makeUnion( geoms );
6410+
6411+
GEOSGeometry* geomCollection = 0;
6412+
geomCollection = createGeosCollection( GEOS_GEOMETRYCOLLECTION, geoms );
6413+
GEOSGeometry* geomUnion = GEOSUnaryUnion( geomCollection );
6414+
GEOSGeom_destroy( geomCollection );
64136415
QgsGeometry *ret = new QgsGeometry();
6414-
ret->fromGeos( unioned );
6416+
ret->fromGeos( geomUnion );
64156417
return ret;
64166418
}
64176419

src/core/symbology-ng/qgsinvertedpolygonrenderer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void QgsInvertedPolygonRenderer::startRender( QgsRenderContext& context, const Q
7373
mSubRenderer->startRender( context, fields );
7474

7575
mFeaturesCategories.clear();
76+
mSymbolCategories.clear();
7677
mFeatureDecorations.clear();
7778
mFields = fields;
7879

@@ -279,6 +280,13 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
279280
}
280281
mSubRenderer->renderFeature( feat, mContext );
281282
}
283+
for ( FeatureCategoryVector::iterator cit = mFeaturesCategories.begin(); cit != mFeaturesCategories.end(); ++cit )
284+
{
285+
foreach( QgsGeometry* g, cit->geometries )
286+
{
287+
delete g;
288+
}
289+
}
282290

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

0 commit comments

Comments
 (0)