Skip to content

Commit

Permalink
Close active iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Jun 21, 2013
1 parent 0c88963 commit 6876540
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -35,6 +35,7 @@ QgsOgrFeatureIterator::QgsOgrFeatureIterator( QgsOgrProvider* p, const QgsFeatur
: QgsAbstractFeatureIterator( request ), P( p ), ogrDataSource(0), ogrLayer(0), mSubsetStringSet(false)
{
mFeatureFetched = false;
P->mActiveIterators.insert( this );

ogrDataSource = OGROpen( TO8F( P->filePath() ), false, NULL );

Expand Down Expand Up @@ -159,6 +160,8 @@ bool QgsOgrFeatureIterator::close()
if ( mClosed )
return false;

P->mActiveIterators.remove( this );

if (mSubsetStringSet)
{
OGR_DS_ReleaseResultSet(ogrDataSource, ogrLayer );
Expand Down
6 changes: 5 additions & 1 deletion src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -209,7 +209,6 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
, ogrDriver( 0 )
, valid( false )
, featuresCounted( -1 )
, mActiveIterator( 0 )
{
QgsCPLErrorHandler handler;

Expand Down Expand Up @@ -362,6 +361,11 @@ QgsOgrProvider::~QgsOgrProvider()
{
// Do we need to close all active iterators here?

foreach ( QgsOgrFeatureIterator* it, mActiveIterators )
{
it->close();
}

if ( ogrLayer != ogrOrigLayer )
{
OGR_DS_ReleaseResultSet( ogrDataSource, ogrLayer );
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrprovider.h
Expand Up @@ -339,5 +339,5 @@ class QgsOgrProvider : public QgsVectorDataProvider
bool syncToDisc();

friend class QgsOgrFeatureIterator;
QgsOgrFeatureIterator* mActiveIterator; //!< pointer to currently active iterator (0 if none)
QSet< QgsOgrFeatureIterator*> mActiveIterators;
};

0 comments on commit 6876540

Please sign in to comment.