diff options
author | Guido van Rossum <guido@python.org> | 1997-09-05 19:11:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-09-05 19:11:53 (GMT) |
commit | d6bf45bcf669a13b2d8c3996b466c5171eca0e53 (patch) | |
tree | 03cc0aabc55755d593b9f66d7927987efbf6a114 /Python/pythonrun.c | |
parent | f394f56c2bda5a3055b1f08e17882dfa39bbdf34 (diff) | |
download | cpython-d6bf45bcf669a13b2d8c3996b466c5171eca0e53.zip cpython-d6bf45bcf669a13b2d8c3996b466c5171eca0e53.tar.gz cpython-d6bf45bcf669a13b2d8c3996b466c5171eca0e53.tar.bz2 |
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.
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index c7832dc..610ec7a 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -761,10 +761,14 @@ PyErr_Print() /* only print colon if the str() of the 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); 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) |