Skip to content
Permalink
Browse files

Protect spatialite connection (dis)connection with a mutex

(cherry-picked from c910187)
  • Loading branch information
nyalldawson committed Jul 16, 2018
1 parent d4c6efa commit 1644d9876f3528b025f7cb710dd44e34ca1a9fc8
@@ -666,6 +666,7 @@ bool QgsSpatiaLiteConnection::isDeclaredHidden( sqlite3 *handle, const QString &


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


bool QgsSqliteHandle::checkMetadata( sqlite3 *handle )
@@ -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 ) )
{
@@ -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 )
;
@@ -762,6 +765,7 @@ void QgsSqliteHandle::closeDb( QgsSqliteHandle *&handle )

void QgsSqliteHandle::closeAll()
{
QMutexLocker locker( &sHandleMutex );
qDeleteAll( sHandles );
sHandles.clear();
}
@@ -17,6 +17,7 @@

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

#include "qgsspatialiteutils.h"

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

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


0 comments on commit 1644d98

Please sign in to comment.
You can’t perform that action at this time.