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

Skip to content

Commit 2e63b73

Browse files
committed
Fix refleak in PyErr_Display().
1 parent 857b300 commit 2e63b73

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

Python/pythonrun.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11151115
err = PyFile_WriteString("<unknown>", f);
11161116
else {
11171117
char* modstr = PyString_AsString(moduleName);
1118+
Py_DECREF(moduleName);
11181119
if (modstr && strcmp(modstr, "exceptions"))
11191120
{
11201121
err = PyFile_WriteString(modstr, f);
@@ -1130,21 +1131,19 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
11301131
}
11311132
else
11321133
err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
1133-
if (err == 0) {
1134-
if (value != Py_None) {
1135-
PyObject *s = PyObject_Str(value);
1136-
/* only print colon if the str() of the
1137-
object is not the empty string
1138-
*/
1139-
if (s == NULL)
1140-
err = -1;
1141-
else if (!PyString_Check(s) ||
1142-
PyString_GET_SIZE(s) != 0)
1143-
err = PyFile_WriteString(": ", f);
1144-
if (err == 0)
1145-
err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
1146-
Py_XDECREF(s);
1147-
}
1134+
if (err == 0 && (value != Py_None)) {
1135+
PyObject *s = PyObject_Str(value);
1136+
/* only print colon if the str() of the
1137+
object is not the empty string
1138+
*/
1139+
if (s == NULL)
1140+
err = -1;
1141+
else if (!PyString_Check(s) ||
1142+
PyString_GET_SIZE(s) != 0)
1143+
err = PyFile_WriteString(": ", f);
1144+
if (err == 0)
1145+
err = PyFile_WriteObject(s, f, Py_PRINT_RAW);
1146+
Py_XDECREF(s);
11481147
}
11491148
if (err == 0)
11501149
err = PyFile_WriteString("\n", f);

0 commit comments

Comments
 (0)