@@ -1098,8 +1098,8 @@ PyErr_PrintEx(int set_sys_last_vars)
10981098void PyErr_Display (PyObject * exception , PyObject * value , PyObject * tb )
10991099{
11001100 int err = 0 ;
1101- PyObject * v = value ;
11021101 PyObject * f = PySys_GetObject ("stderr" );
1102+ Py_INCREF (value );
11031103 if (f == NULL )
11041104 fprintf (stderr , "lost sys.stderr\n" );
11051105 else {
@@ -1109,12 +1109,12 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11091109 if (tb && tb != Py_None )
11101110 err = PyTraceBack_Print (tb , f );
11111111 if (err == 0 &&
1112- PyObject_HasAttrString (v , "print_file_and_line" ))
1112+ PyObject_HasAttrString (value , "print_file_and_line" ))
11131113 {
11141114 PyObject * message ;
11151115 const char * filename , * text ;
11161116 int lineno , offset ;
1117- if (!parse_syntax_error (v , & message , & filename ,
1117+ if (!parse_syntax_error (value , & message , & filename ,
11181118 & lineno , & offset , & text ))
11191119 PyErr_Clear ();
11201120 else {
@@ -1130,7 +1130,8 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11301130 PyFile_WriteString ("\n" , f );
11311131 if (text != NULL )
11321132 print_error_text (f , offset , text );
1133- v = message ;
1133+ Py_DECREF (value );
1134+ value = message ;
11341135 /* Can't be bothered to check all those
11351136 PyFile_WriteString() calls */
11361137 if (PyErr_Occurred ())
@@ -1167,8 +1168,8 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11671168 else
11681169 err = PyFile_WriteObject (exception , f , Py_PRINT_RAW );
11691170 if (err == 0 ) {
1170- if (v != NULL && v != Py_None ) {
1171- PyObject * s = PyObject_Str (v );
1171+ if (value != Py_None ) {
1172+ PyObject * s = PyObject_Str (value );
11721173 /* only print colon if the str() of the
11731174 object is not the empty string
11741175 */
@@ -1185,6 +1186,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11851186 if (err == 0 )
11861187 err = PyFile_WriteString ("\n" , f );
11871188 }
1189+ Py_DECREF (value );
11881190 /* If an error happened here, don't show it.
11891191 XXX This is wrong, but too many callers rely on this behavior. */
11901192 if (err != 0 )
0 commit comments