Skip to content

Commit a1e826e

Browse files
committed
Avoid a segfault when python code fails
PyRun_StringFlags: Returns the result of executing the code as a Python object, or NULL if an exception was raised.
1 parent 5a74c68 commit a1e826e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/python/qgspythonutilsimpl.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ bool QgsPythonUtilsImpl::runStringUnsafe( const QString& command, bool single )
300300
// (non-unicode strings can be mangled)
301301
PyObject* obj = PyRun_String( command.toUtf8().data(), single ? Py_single_input : Py_file_input, mMainDict, mMainDict );
302302
bool res = nullptr == PyErr_Occurred();
303-
Py_DECREF( obj );
303+
if ( obj )
304+
{
305+
Py_DECREF( obj );
306+
}
304307

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

0 commit comments

Comments
 (0)