Skip to content

Commit

Permalink
Fix a thread safety issue in postgres provider
Browse files Browse the repository at this point in the history
Fix access to:
- PQexecNR
- openCursor
- closeCursor
- uniqueCursorName

Partial backport from eb08839
  • Loading branch information
Hugo Mercier committed Jan 16, 2019
1 parent 5aed4d7 commit 7ab24c8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;

Expand All @@ -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 );
}

Expand Down

0 comments on commit 7ab24c8

Please sign in to comment.