Skip to content

Commit

Permalink
Fix major(?) memory leak with python code execution
Browse files Browse the repository at this point in the history
(cherry-picked from 73733a6)
  • Loading branch information
nyalldawson committed May 16, 2016
1 parent 804ac7e commit 8f0ee1f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/python/qgspythonutilsimpl.cpp
Expand Up @@ -298,9 +298,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 );

This comment has been minimized.

Copy link
@elpaso

elpaso May 23, 2016

Contributor

Segfault here with 2.14.3
test with qgis --code 'some_not_existant_path.py'

This comment has been minimized.

Copy link
@elpaso

elpaso May 23, 2016

Contributor

PyRun_StringFlags: Returns the result of executing
the code as a Python object, or NULL if an exception was raised.

Need to check for obj before decref.


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

Py_XDECREF( res );

This comment has been minimized.

Copy link
@elpaso

elpaso May 23, 2016

Contributor

Same here probably.


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

Expand Down

0 comments on commit 8f0ee1f

Please sign in to comment.