Skip to content
Permalink
Browse files

[pal] Fix memory leak due to buggy pal::rtree iterator implementation

  • Loading branch information
nyalldawson committed Aug 26, 2015
1 parent bea3d72 commit 00405c73ff21bf9f4716e03c2a3bd7e07e384273
Showing with 6 additions and 7 deletions.
  1. +5 −7 src/core/qgslabelsearchtree.cpp
  2. +1 −0 src/core/qgslabelsearchtree.h
@@ -86,17 +86,15 @@ bool QgsLabelSearchTree::insertLabel( LabelPosition* labelPos, int featureId, co
QgsLabelPosition* newEntry = new QgsLabelPosition( featureId, labelPos->getAlpha(), cornerPoints, QgsRectangle( c_min[0], c_min[1], c_max[0], c_max[1] ),
labelPos->getWidth(), labelPos->getHeight(), layerName, labeltext, labelfont, labelPos->getUpsideDown(), diagram, pinned );
mSpatialIndex.Insert( c_min, c_max, newEntry );
mOwnedPositions << newEntry;
return true;
}

void QgsLabelSearchTree::clear()
{
RTree<QgsLabelPosition*, double, 2, double>::Iterator indexIt;
mSpatialIndex.GetFirst( indexIt );
while ( !mSpatialIndex.IsNull( indexIt ) )
{
delete mSpatialIndex.GetAt( indexIt );
mSpatialIndex.GetNext( indexIt );
}
mSpatialIndex.RemoveAll();

//PAL rtree iterator is buggy and doesn't iterate over all items, so we can't iterate through the tree to delete positions
qDeleteAll( mOwnedPositions );
mOwnedPositions.clear();
}
@@ -60,6 +60,7 @@ class CORE_EXPORT QgsLabelSearchTree
private:
// set as mutable because RTree template is not const-correct
mutable RTree<QgsLabelPosition*, double, 2, double> mSpatialIndex;
QList< QgsLabelPosition* > mOwnedPositions;
};

#endif // QGSLABELTREE_H

0 comments on commit 00405c7

Please sign in to comment.
You can’t perform that action at this time.