Skip to content

Commit

Permalink
Fix crash on exit: Close all cached sqlite connections
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 24, 2014
1 parent b6e8f01 commit 4e36059
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/providers/spatialite/qgsspatialiteconnection.cpp
Expand Up @@ -800,6 +800,18 @@ void QgsSqliteHandle::closeDb( QgsSqliteHandle * &handle )
handle = NULL;
}

void QgsSqliteHandle::closeAll()
{
QMap < QString, QgsSqliteHandle * >::iterator i;
for ( i = handles.begin(); i != handles.end(); ++i )
{
i.value()->sqliteClose();
delete i.value();
}

handles.clear();
}

void QgsSqliteHandle::sqliteClose()
{
if ( sqlite_handle )
Expand Down
6 changes: 6 additions & 0 deletions src/providers/spatialite/qgsspatialiteconnection.h
Expand Up @@ -155,6 +155,12 @@ class QgsSqliteHandle
static QgsSqliteHandle *openDb( const QString & dbPath, bool shared = true );
static bool checkMetadata( sqlite3 * handle );
static void closeDb( QgsSqliteHandle * &handle );

/**
* Will close any cached connection
* To be called on application exit
*/
static void closeAll();
//static void closeDb( QMap < QString, QgsSqliteHandle * >&handlesRO, QgsSqliteHandle * &handle );

private:
Expand Down
5 changes: 5 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -5560,3 +5560,8 @@ QGISEXTERN QString getStyleById( const QString& uri, QString styleId, QString& e
sqlite3_free_table( results );
return style;
}

QGISEXTERN void cleanupProvider()
{
QgsSqliteHandle::closeAll();
}

0 comments on commit 4e36059

Please sign in to comment.