Skip to content
Permalink
Browse files

Close active iterators

  • Loading branch information
NathanW2 committed Jun 21, 2013
1 parent 0c88963 commit 6876540302bd0c2e75ca6c97db8a99765fb10f5d
@@ -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 );

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

P->mActiveIterators.remove( this );

if (mSubsetStringSet)
{
OGR_DS_ReleaseResultSet(ogrDataSource, ogrLayer );
@@ -209,7 +209,6 @@ QgsOgrProvider::QgsOgrProvider( QString const & uri )
, ogrDriver( 0 )
, valid( false )
, featuresCounted( -1 )
, mActiveIterator( 0 )
{
QgsCPLErrorHandler handler;

@@ -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 );
@@ -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.
You can’t perform that action at this time.