Skip to content

Commit 5d2c683

Browse files
committed
Lost reference.
1 parent 1eb4bfc commit 5d2c683

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Python/pythonrun.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ PyErr_PrintEx(int set_sys_last_vars)
10861086
void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
10871087
{
10881088
int err = 0;
1089-
PyObject *v = value;
10901089
PyObject *f = PySys_GetObject("stderr");
1090+
Py_INCREF(value);
10911091
if (f == NULL)
10921092
fprintf(stderr, "lost sys.stderr\n");
10931093
else {
@@ -1097,12 +1097,12 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
10971097
if (tb && tb != Py_None)
10981098
err = PyTraceBack_Print(tb, f);
10991099
if (err == 0 &&
1100-
PyObject_HasAttrString(v, "print_file_and_line"))
1100+
PyObject_HasAttrString(value, "print_file_and_line"))
11011101
{
11021102
PyObject *message;
11031103
const char *filename, *text;
11041104
int lineno, offset;
1105-
if (!parse_syntax_error(v, &message, &filename,
1105+
if (!parse_syntax_error(value, &message, &filename,
11061106
&lineno, &offset, &text))
11071107
PyErr_Clear();
11081108
else {
@@ -1118,7 +1118,8 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11181118
PyFile_WriteString("\n", f);
11191119
if (text != NULL)
11201120
print_error_text(f, offset, text);
1121-
v = message;
1121+
Py_DECREF(value);
1122+
value = message;
11221123
/* Can't be bothered to check all those
11231124
PyFile_WriteString() calls */
11241125
if (PyErr_Occurred())
@@ -1155,8 +1156,8 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11551156
else
11561157
err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
11571158
if (err == 0) {
1158-
if (v != NULL && v != Py_None) {
1159-
PyObject *s = PyObject_Str(v);
1159+
if (value != Py_None) {
1160+
PyObject *s = PyObject_Str(value);
11601161
/* only print colon if the str() of the
11611162
object is not the empty string
11621163
*/
@@ -1173,6 +1174,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11731174
if (err == 0)
11741175
err = PyFile_WriteString("\n", f);
11751176
}
1177+
Py_DECREF(value);
11761178
/* If an error happened here, don't show it.
11771179
XXX This is wrong, but too many callers rely on this behavior. */
11781180
if (err != 0)

0 commit comments

Comments
 (0)