mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
f394f56c2b
commit
d6bf45bcf6
1 changed files with 6 additions and 2 deletions
|
@ -761,10 +761,14 @@ PyErr_Print()
|
||||||
/* only print colon if the str() of the
|
/* only print colon if the str() of the
|
||||||
object is not the empty string
|
object is not the empty string
|
||||||
*/
|
*/
|
||||||
if (s && strcmp(PyString_AsString(s), ""))
|
if (s == NULL)
|
||||||
|
err = -1;
|
||||||
|
else if (!PyString_Check(s) ||
|
||||||
|
PyString_GET_SIZE(s) != 0)
|
||||||
err = PyFile_WriteString(": ", f);
|
err = PyFile_WriteString(": ", f);
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
err = PyFile_WriteObject(v, f, Py_PRINT_RAW);
|
err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
|
||||||
|
Py_XDECREF(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue