Skip to content
Permalink
Browse files

Fix major(?) memory leak with python code execution

(cherry-picked from 73733a6)
  • Loading branch information
nyalldawson committed May 16, 2016
1 parent 804ac7e commit 8f0ee1fe27f99277f08f01974e885abdc4654322
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/python/qgspythonutilsimpl.cpp
@@ -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 );
@@ -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 );

0 comments on commit 8f0ee1f

Please sign in to comment.
You can’t perform that action at this time.