Skip to content
Permalink
Browse files

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 0d21e640a908bdb669a29127de14a90fedc9112e
@@ -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 );
@@ -15,6 +15,7 @@
import qgis # NOQA

import os
import shutil
import tempfile

from qgis.core import QgsVectorLayer, QgsPoint, QgsFeature
@@ -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.
You can’t perform that action at this time.