Skip to content

Commit 00405c7

Browse files
committed
[pal] Fix memory leak due to buggy pal::rtree iterator implementation
1 parent bea3d72 commit 00405c7

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/core/qgslabelsearchtree.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,15 @@ bool QgsLabelSearchTree::insertLabel( LabelPosition* labelPos, int featureId, co
8686
QgsLabelPosition* newEntry = new QgsLabelPosition( featureId, labelPos->getAlpha(), cornerPoints, QgsRectangle( c_min[0], c_min[1], c_max[0], c_max[1] ),
8787
labelPos->getWidth(), labelPos->getHeight(), layerName, labeltext, labelfont, labelPos->getUpsideDown(), diagram, pinned );
8888
mSpatialIndex.Insert( c_min, c_max, newEntry );
89+
mOwnedPositions << newEntry;
8990
return true;
9091
}
9192

9293
void QgsLabelSearchTree::clear()
9394
{
94-
RTree<QgsLabelPosition*, double, 2, double>::Iterator indexIt;
95-
mSpatialIndex.GetFirst( indexIt );
96-
while ( !mSpatialIndex.IsNull( indexIt ) )
97-
{
98-
delete mSpatialIndex.GetAt( indexIt );
99-
mSpatialIndex.GetNext( indexIt );
100-
}
10195
mSpatialIndex.RemoveAll();
96+
97+
//PAL rtree iterator is buggy and doesn't iterate over all items, so we can't iterate through the tree to delete positions
98+
qDeleteAll( mOwnedPositions );
99+
mOwnedPositions.clear();
102100
}

src/core/qgslabelsearchtree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class CORE_EXPORT QgsLabelSearchTree
6060
private:
6161
// set as mutable because RTree template is not const-correct
6262
mutable RTree<QgsLabelPosition*, double, 2, double> mSpatialIndex;
63+
QList< QgsLabelPosition* > mOwnedPositions;
6364
};
6465

6566
#endif // QGSLABELTREE_H

0 commit comments

Comments
 (0)