Skip to content

Commit 8f0ee1f

Browse files
committed
Fix major(?) memory leak with python code execution
(cherry-picked from 73733a6)
1 parent 804ac7e commit 8f0ee1f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/python/qgspythonutilsimpl.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single )
298298
// TODO: convert special characters from unicode strings u"..." to \uXXXX
299299
// so that they're not mangled to utf-8
300300
// (non-unicode strings can be mangled)
301-
PyRun_String( command.toUtf8().data(), single ? Py_single_input : Py_file_input, mMainDict, mMainDict );
302-
301+
PyObject* obj = PyRun_String( command.toUtf8().data(), single ? Py_single_input : Py_file_input, mMainDict, mMainDict );
303302
bool res = nullptr == PyErr_Occurred();
303+
Py_DECREF( obj );
304304

305305
// we are done calling python API, release global interpreter lock
306306
PyGILState_Release( gstate );
@@ -581,6 +581,8 @@ bool QgsPythonUtilsImpl::evalString( const QString& command, QString& result )
581581
if ( success )
582582
result = PyObjectToQString( res );
583583

584+
Py_XDECREF( res );
585+
584586
// we are done calling python API, release global interpreter lock
585587
PyGILState_Release( gstate );
586588

0 commit comments

Comments
 (0)