Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Spatialite] Fix crash on iterator closing if connection failed.
If an iterator fails to open the spatialite database (mHandle == nullptr
in QgsSpatiaLiteFeatureIterator::QgsSpatiaLiteFeatureIterator() ),
a crash will occur at the destruction of the QgsSpatiaLiteFeatureSource,
due to the iterator not being removed from the list of active iterators.

Currently QgsSpatiaLiteFeatureIterator::close() does not call
iteratorClosed() if mHandle is invalid, which later causes
QgsAbstractFeatureSource::~QgsAbstractFeatureSource() to try calling
the close() method of a now defunct iterator.

If not applying the patch, the added test case crashes with:

177: src/providers/spatialite/qgsspatialiteconnection.cpp: 736: (openDb) [1ms] New sqlite connection for /tmp/test.sqlite.corrupt
177: src/providers/spatialite/qgsspatialiteconnection.cpp: 750: (openDb) [1ms] Failure while connecting to: /tmp/test.sqlite.corrupt
177:
177: invalid metadata tables
177: src/core/qgsfeaturerequest.cpp: 259: (~QgsAbstractFeatureSource) [0ms] closing active iterator
177: CMake Error at PyQgsSpatialiteProvider.cmake:22 (MESSAGE):
177:   Test failed: Segmentation fault
(cherry picked from commit 2b15eaa)
  • Loading branch information
rouault authored and jef-n committed Mar 25, 2016
1 parent 9f125eb commit ea74db3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Expand Up @@ -123,6 +123,12 @@ bool QgsSpatiaLiteFeatureIterator::close()

iteratorClosed();

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

if ( sqliteStatement )
{
sqlite3_finalize( sqliteStatement );
Expand Down

0 comments on commit ea74db3

Please sign in to comment.