From 6db7e2fb8d6b7d9364a1070b10e5d7741d5eee10 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Fri, 28 May 2021 15:38:35 +0200 Subject: [PATCH] Fix deadlock on joins cache Fixes #43287 The critical section was called recursively by a call form the model connected to joinedFieldsChanged. By moving the mutex into a scope we can safely release it before emitting the signal. --- src/core/vector/qgsvectorlayerjoinbuffer.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/vector/qgsvectorlayerjoinbuffer.cpp b/src/core/vector/qgsvectorlayerjoinbuffer.cpp index 5ca5ebbe609f..40c6caf74319 100644 --- a/src/core/vector/qgsvectorlayerjoinbuffer.cpp +++ b/src/core/vector/qgsvectorlayerjoinbuffer.cpp @@ -100,19 +100,21 @@ bool QgsVectorLayerJoinBuffer::addJoin( const QgsVectorLayerJoinInfo &joinInfo ) bool QgsVectorLayerJoinBuffer::removeJoin( const QString &joinLayerId ) { - QMutexLocker locker( &mMutex ); bool res = false; - for ( int i = 0; i < mVectorJoins.size(); ++i ) { - if ( mVectorJoins.at( i ).joinLayerId() == joinLayerId ) + QMutexLocker locker( &mMutex ); + for ( int i = 0; i < mVectorJoins.size(); ++i ) { - if ( QgsVectorLayer *vl = mVectorJoins.at( i ).joinLayer() ) + if ( mVectorJoins.at( i ).joinLayerId() == joinLayerId ) { - disconnect( vl, &QgsVectorLayer::updatedFields, this, &QgsVectorLayerJoinBuffer::joinedLayerUpdatedFields ); - } + if ( QgsVectorLayer *vl = mVectorJoins.at( i ).joinLayer() ) + { + disconnect( vl, &QgsVectorLayer::updatedFields, this, &QgsVectorLayerJoinBuffer::joinedLayerUpdatedFields ); + } - mVectorJoins.removeAt( i ); - res = true; + mVectorJoins.removeAt( i ); + res = true; + } } }