Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Protect spatialite connection (dis)connection with a mutex
(cherry-picked from c910187)
  • Loading branch information
nyalldawson committed Jul 17, 2018
1 parent d4c6efa commit 1644d98
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/providers/spatialite/qgsspatialiteconnection.cpp
Expand Up @@ -666,6 +666,7 @@ bool QgsSpatiaLiteConnection::isDeclaredHidden( sqlite3 *handle, const QString &


QMap < QString, QgsSqliteHandle * > QgsSqliteHandle::sHandles;
QMutex QgsSqliteHandle::sHandleMutex;


bool QgsSqliteHandle::checkMetadata( sqlite3 *handle )
Expand Down Expand Up @@ -696,6 +697,7 @@ bool QgsSqliteHandle::checkMetadata( sqlite3 *handle )
QgsSqliteHandle *QgsSqliteHandle::openDb( const QString &dbPath, bool shared )
{
//QMap < QString, QgsSqliteHandle* >&handles = QgsSqliteHandle::handles;
QMutexLocker locker( &sHandleMutex );

if ( shared && sHandles.contains( dbPath ) )
{
Expand Down Expand Up @@ -743,6 +745,7 @@ void QgsSqliteHandle::closeDb( QgsSqliteHandle *&handle )
}
else
{
QMutexLocker locker( &sHandleMutex );
QMap < QString, QgsSqliteHandle * >::iterator i;
for ( i = sHandles.begin(); i != sHandles.end() && i.value() != handle; ++i )
;
Expand All @@ -762,6 +765,7 @@ void QgsSqliteHandle::closeDb( QgsSqliteHandle *&handle )

void QgsSqliteHandle::closeAll()
{
QMutexLocker locker( &sHandleMutex );
qDeleteAll( sHandles );
sHandles.clear();
}
2 changes: 2 additions & 0 deletions src/providers/spatialite/qgsspatialiteconnection.h
Expand Up @@ -17,6 +17,7 @@

#include <QStringList>
#include <QObject>
#include <QMutex>

#include "qgsspatialiteutils.h"

Expand Down Expand Up @@ -178,6 +179,7 @@ class QgsSqliteHandle
bool mIsValid;

static QMap < QString, QgsSqliteHandle * > sHandles;
static QMutex sHandleMutex;
};


Expand Down

0 comments on commit 1644d98

Please sign in to comment.