Skip to content

Commit bcbc46b

Browse files
committedJan 28, 2018
Fix possible GIL deadlock when iterating features in python
and an exception is thrown
1 parent 285bb06 commit bcbc46b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
 

‎python/core/qgsfeatureiterator.sip.in

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,15 @@ Wrapper for iterator of features from vector data provider or vector layer
201201

202202
SIP_PYOBJECT __next__();
203203
%MethodCode
204-
QgsFeature *f = new QgsFeature;
205-
if ( sipCpp->nextFeature( *f ) )
206-
sipRes = sipConvertFromType( f, sipType_QgsFeature, Py_None );
204+
std::unique_ptr< QgsFeature > f = qgis::make_unique< QgsFeature >();
205+
bool result = false;
206+
Py_BEGIN_ALLOW_THREADS
207+
result = ( sipCpp->nextFeature( *f ) );
208+
Py_END_ALLOW_THREADS
209+
if ( result )
210+
sipRes = sipConvertFromType( f.release(), sipType_QgsFeature, Py_None );
207211
else
208212
{
209-
delete f;
210213
PyErr_SetString( PyExc_StopIteration, "" );
211214
}
212215
%End

‎src/core/qgsfeatureiterator.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,15 @@ class CORE_EXPORT QgsFeatureIterator
276276

277277
SIP_PYOBJECT __next__();
278278
% MethodCode
279-
QgsFeature *f = new QgsFeature;
280-
if ( sipCpp->nextFeature( *f ) )
281-
sipRes = sipConvertFromType( f, sipType_QgsFeature, Py_None );
279+
std::unique_ptr< QgsFeature > f = qgis::make_unique< QgsFeature >();
280+
bool result = false;
281+
Py_BEGIN_ALLOW_THREADS
282+
result = ( sipCpp->nextFeature( *f ) );
283+
Py_END_ALLOW_THREADS
284+
if ( result )
285+
sipRes = sipConvertFromType( f.release(), sipType_QgsFeature, Py_None );
282286
else
283287
{
284-
delete f;
285288
PyErr_SetString( PyExc_StopIteration, "" );
286289
}
287290
% End

0 commit comments

Comments
 (0)
Please sign in to comment.