Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2944 from rouault/fix_crash_on_invalid_spatialite…
…_iterator

[Spatialite] Fix crash on iterator closing if connection failed.
  • Loading branch information
jef-n committed Mar 24, 2016
2 parents ea4a0e2 + 2b15eaa commit 0d21e64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Expand Up @@ -235,11 +235,17 @@ bool QgsSpatiaLiteFeatureIterator::rewind()

bool QgsSpatiaLiteFeatureIterator::close()
{
if ( !mHandle )
if ( mClosed )
return false;

iteratorClosed();

if ( !mHandle )
{
mClosed = true;
return false;
}

if ( sqliteStatement )
{
sqlite3_finalize( sqliteStatement );
Expand Down
11 changes: 11 additions & 0 deletions tests/src/python/test_provider_spatialite.py
Expand Up @@ -15,6 +15,7 @@
import qgis # NOQA

import os
import shutil
import tempfile

from qgis.core import QgsVectorLayer, QgsPoint, QgsFeature
Expand Down Expand Up @@ -201,6 +202,16 @@ def test_case(self):
fields = [f.name() for f in l.dataProvider().fields()]
assert('Geometry' not in fields)

def test_invalid_iterator(self):
""" Test invalid iterator """
corrupt_dbname = self.dbname + '.corrupt'
shutil.copy(self.dbname, corrupt_dbname)
layer = QgsVectorLayer("dbname=%s table=test_pg (geometry)" % corrupt_dbname, "test_pg", "spatialite")
# Corrupt the database
open(corrupt_dbname, 'wb').write('')
layer.getFeatures()
layer = None
os.unlink(corrupt_dbname)

if __name__ == '__main__':
unittest.main()

0 comments on commit 0d21e64

Please sign in to comment.