From bcbc46b56ba541ee03a323b2cdce998403e9f1ab Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Sat, 27 Jan 2018 21:52:55 +1000 Subject: [PATCH] Fix possible GIL deadlock when iterating features in python and an exception is thrown --- python/core/qgsfeatureiterator.sip.in | 11 +++++++---- src/core/qgsfeatureiterator.h | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/python/core/qgsfeatureiterator.sip.in b/python/core/qgsfeatureiterator.sip.in index a15827e6f177..f2e6d2fcf9b3 100644 --- a/python/core/qgsfeatureiterator.sip.in +++ b/python/core/qgsfeatureiterator.sip.in @@ -201,12 +201,15 @@ Wrapper for iterator of features from vector data provider or vector layer SIP_PYOBJECT __next__(); %MethodCode - QgsFeature *f = new QgsFeature; - if ( sipCpp->nextFeature( *f ) ) - sipRes = sipConvertFromType( f, sipType_QgsFeature, Py_None ); + std::unique_ptr< QgsFeature > f = qgis::make_unique< QgsFeature >(); + bool result = false; + Py_BEGIN_ALLOW_THREADS + result = ( sipCpp->nextFeature( *f ) ); + Py_END_ALLOW_THREADS + if ( result ) + sipRes = sipConvertFromType( f.release(), sipType_QgsFeature, Py_None ); else { - delete f; PyErr_SetString( PyExc_StopIteration, "" ); } %End diff --git a/src/core/qgsfeatureiterator.h b/src/core/qgsfeatureiterator.h index 3e655dc69b95..95aecd497733 100644 --- a/src/core/qgsfeatureiterator.h +++ b/src/core/qgsfeatureiterator.h @@ -276,12 +276,15 @@ class CORE_EXPORT QgsFeatureIterator SIP_PYOBJECT __next__(); % MethodCode - QgsFeature *f = new QgsFeature; - if ( sipCpp->nextFeature( *f ) ) - sipRes = sipConvertFromType( f, sipType_QgsFeature, Py_None ); + std::unique_ptr< QgsFeature > f = qgis::make_unique< QgsFeature >(); + bool result = false; + Py_BEGIN_ALLOW_THREADS + result = ( sipCpp->nextFeature( *f ) ); + Py_END_ALLOW_THREADS + if ( result ) + sipRes = sipConvertFromType( f.release(), sipType_QgsFeature, Py_None ); else { - delete f; PyErr_SetString( PyExc_StopIteration, "" ); } % End