Skip to content

Commit 1644d98

Browse files
committed
Protect spatialite connection (dis)connection with a mutex
(cherry-picked from c910187)
1 parent d4c6efa commit 1644d98

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/providers/spatialite/qgsspatialiteconnection.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ bool QgsSpatiaLiteConnection::isDeclaredHidden( sqlite3 *handle, const QString &
666666

667667

668668
QMap < QString, QgsSqliteHandle * > QgsSqliteHandle::sHandles;
669+
QMutex QgsSqliteHandle::sHandleMutex;
669670

670671

671672
bool QgsSqliteHandle::checkMetadata( sqlite3 *handle )
@@ -696,6 +697,7 @@ bool QgsSqliteHandle::checkMetadata( sqlite3 *handle )
696697
QgsSqliteHandle *QgsSqliteHandle::openDb( const QString &dbPath, bool shared )
697698
{
698699
//QMap < QString, QgsSqliteHandle* >&handles = QgsSqliteHandle::handles;
700+
QMutexLocker locker( &sHandleMutex );
699701

700702
if ( shared && sHandles.contains( dbPath ) )
701703
{
@@ -743,6 +745,7 @@ void QgsSqliteHandle::closeDb( QgsSqliteHandle *&handle )
743745
}
744746
else
745747
{
748+
QMutexLocker locker( &sHandleMutex );
746749
QMap < QString, QgsSqliteHandle * >::iterator i;
747750
for ( i = sHandles.begin(); i != sHandles.end() && i.value() != handle; ++i )
748751
;
@@ -762,6 +765,7 @@ void QgsSqliteHandle::closeDb( QgsSqliteHandle *&handle )
762765

763766
void QgsSqliteHandle::closeAll()
764767
{
768+
QMutexLocker locker( &sHandleMutex );
765769
qDeleteAll( sHandles );
766770
sHandles.clear();
767771
}

src/providers/spatialite/qgsspatialiteconnection.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <QStringList>
1919
#include <QObject>
20+
#include <QMutex>
2021

2122
#include "qgsspatialiteutils.h"
2223

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

180181
static QMap < QString, QgsSqliteHandle * > sHandles;
182+
static QMutex sHandleMutex;
181183
};
182184

183185

0 commit comments

Comments
 (0)