Skip to content
Permalink
Browse files

Fix a thread safety issue in postgres provider

Fix access to:
- PQexecNR
- openCursor
- closeCursor
- uniqueCursorName

Partial backport from eb08839
  • Loading branch information
Hugo Mercier
Hugo Mercier committed Jan 16, 2019
1 parent 5aed4d7 commit 7ab24c8c647c8db77ebe3b658b8194a0671b1783
Showing with 5 additions and 0 deletions.
  1. +5 −0 src/providers/postgres/qgspostgresconn.cpp
@@ -1104,6 +1104,8 @@ PGresult *QgsPostgresConn::PQexec( const QString &query, bool logError ) const

bool QgsPostgresConn::openCursor( const QString &cursorName, const QString &sql )
{
QMutexLocker locker( &mLock ); // to protect access to mOpenCursors

if ( mOpenCursors++ == 0 && !mTransaction )
{
QgsDebugMsgLevel( QStringLiteral( "Starting read-only transaction: %1" ).arg( mPostgresqlVersion ), 4 );
@@ -1119,6 +1121,8 @@ bool QgsPostgresConn::openCursor( const QString &cursorName, const QString &sql

bool QgsPostgresConn::closeCursor( const QString &cursorName )
{
QMutexLocker locker( &mLock ); // to protect access to mOpenCursors

if ( !PQexecNR( QStringLiteral( "CLOSE %1" ).arg( cursorName ) ) )
return false;

@@ -1133,6 +1137,7 @@ bool QgsPostgresConn::closeCursor( const QString &cursorName )

QString QgsPostgresConn::uniqueCursorName()
{
QMutexLocker locker( &mLock ); // to protect access to mNextCursorId
return QStringLiteral( "qgis_%1" ).arg( ++mNextCursorId );
}

0 comments on commit 7ab24c8

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