Skip to content

Commit

Permalink
[pal] Fix memory leak due to buggy pal::rtree iterator implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 26, 2015
1 parent bea3d72 commit 00405c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/core/qgslabelsearchtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions src/core/qgslabelsearchtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.