Fix invalid free in SWIG_Python_AddErrMesg

Closes #1331
This commit is contained in:
William S Fulton 2018-09-28 07:08:12 +01:00
commit 142d4062df

View file

@ -1484,14 +1484,13 @@ SWIG_Python_AddErrMesg(const char* mesg, int infront)
if (value) { if (value) {
PyObject *old_str = PyObject_Str(value); PyObject *old_str = PyObject_Str(value);
const char *tmp = SWIG_Python_str_AsChar(old_str); const char *tmp = SWIG_Python_str_AsChar(old_str);
if (!tmp) const char *errmesg = tmp ? tmp : "Invalid error message";
tmp = "Invalid error message";
Py_XINCREF(type); Py_XINCREF(type);
PyErr_Clear(); PyErr_Clear();
if (infront) { if (infront) {
PyErr_Format(type, "%s %s", mesg, tmp); PyErr_Format(type, "%s %s", mesg, errmesg);
} else { } else {
PyErr_Format(type, "%s %s", tmp, mesg); PyErr_Format(type, "%s %s", errmesg, mesg);
} }
SWIG_Python_str_DelForPy3(tmp); SWIG_Python_str_DelForPy3(tmp);
Py_DECREF(old_str); Py_DECREF(old_str);