Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6bf45b

Browse files
committed
Fixed some details of printing the str() of an exception. This fixes
a core dump when __str__() returns a non-string, and plugs a memory leak as well: the result of PyObject_Str() was never DECREFed.
1 parent f394f56 commit d6bf45b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Python/pythonrun.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,14 @@ PyErr_Print()
761761
/* only print colon if the str() of the
762762
object is not the empty string
763763
*/
764-
if (s && strcmp(PyString_AsString(s), ""))
764+
if (s == NULL)
765+
err = -1;
766+
else if (!PyString_Check(s) ||
767+
PyString_GET_SIZE(s) != 0)
765768
err = PyFile_WriteString(": ", f);
766769
if (err == 0)
767-
err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
770+
err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
771+
Py_XDECREF(s);
768772
}
769773
}
770774
if (err == 0)

0 commit comments

Comments
 (0)