From d774c495de208d4bb513db9f6211bc6d62ec2347 Mon Sep 17 00:00:00 2001 From: sbh Date: Wed, 14 Jan 2015 11:20:55 +0300 Subject: [PATCH] Issue #329: avoid app crashes on malformed python feature launching --- src/Config/Config_ModuleReader.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Config/Config_ModuleReader.cpp b/src/Config/Config_ModuleReader.cpp index d0da80ba0..526b9965f 100644 --- a/src/Config/Config_ModuleReader.cpp +++ b/src/Config/Config_ModuleReader.cpp @@ -173,18 +173,21 @@ void Config_ModuleReader::loadScript(const std::string theFileName) { /* aquire python thread */ PyGILState_STATE gstate = PyGILState_Ensure(); - PyObject* module = PyImport_ImportModule(theFileName.c_str()); + PyObject* module = PyImport_ImportModule(theFileName.c_str()); if (!module) { std::string anErrorMsg = "An error occured while importing " + theFileName; //Get detailed error message: if (PyErr_Occurred()) { - PyObject *ptype, *pvalue, *ptraceback; + PyObject *pstr, *ptype, *pvalue, *ptraceback; PyErr_Fetch(&ptype, &pvalue, &ptraceback); - std::string aPyError = std::string(PyString_AsString(pvalue)); + PyErr_NormalizeException(&ptype, &pvalue, &ptraceback); + pstr = PyObject_Str(pvalue); + std::string aPyError = std::string(PyString_AsString(pstr)); if (!aPyError.empty()) { anErrorMsg += ":\n" + aPyError; } + Py_XDECREF(pstr); Py_XDECREF(ptype); Py_XDECREF(pvalue); Py_XDECREF(ptraceback); -- 2.39.2