Skip to content

Commit

Permalink
Fix major(?) memory leak with python code execution
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 10, 2016
1 parent c32966d commit 73733a6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -305,9 +305,9 @@ bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single )
// TODO: convert special characters from unicode strings u"..." to \uXXXX
// so that they're not mangled to utf-8
// (non-unicode strings can be mangled)
PyRun_String( command.toUtf8().data(), single ? Py_single_input : Py_file_input, mMainDict, mMainDict );

PyObject* obj = PyRun_String( command.toUtf8().data(), single ? Py_single_input : Py_file_input, mMainDict, mMainDict );
bool res = nullptr == PyErr_Occurred();
Py_DECREF( obj );

// we are done calling python API, release global interpreter lock
PyGILState_Release( gstate );
Expand Down Expand Up @@ -580,6 +580,8 @@ bool QgsPythonUtilsImpl::evalString( const QString& command, QString& result )
if ( success )
result = PyObjectToQString( res );

Py_XDECREF( res );

// we are done calling python API, release global interpreter lock
PyGILState_Release( gstate );

Expand Down

0 comments on commit 73733a6

Please sign in to comment.