]> granicus.if.org Git - python/commitdiff
Fix refleak in PyErr_Display().
authorBrett Cannon <bcannon@gmail.com>
Thu, 2 Mar 2006 18:34:57 +0000 (18:34 +0000)
committerBrett Cannon <bcannon@gmail.com>
Thu, 2 Mar 2006 18:34:57 +0000 (18:34 +0000)
Python/pythonrun.c

index a98c85ac10d2b374f7eb81c391f3b940286d2e32..1b2b829c3d61cb0d044f334368e9a3c7ea0b6bab 100644 (file)
@@ -1115,6 +1115,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
                                err = PyFile_WriteString("<unknown>", f);
                        else {
                                char* modstr = PyString_AsString(moduleName);
+                               Py_DECREF(moduleName);
                                if (modstr && strcmp(modstr, "exceptions"))
                                {
                                        err = PyFile_WriteString(modstr, f);
@@ -1130,21 +1131,19 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
                }
                else
                        err = PyFile_WriteObject(exception, f, Py_PRINT_RAW);
-               if (err == 0) {
-                       if (value != Py_None) {
-                               PyObject *s = PyObject_Str(value);
-                               /* only print colon if the str() of the
-                                  object is not the empty string
-                               */
-                               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(s, f, Py_PRINT_RAW);
-                               Py_XDECREF(s);
-                       }
+               if (err == 0 && (value != Py_None)) {
+                       PyObject *s = PyObject_Str(value);
+                       /* only print colon if the str() of the
+                          object is not the empty string
+                       */
+                       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(s, f, Py_PRINT_RAW);
+                       Py_XDECREF(s);
                }
                if (err == 0)
                        err = PyFile_WriteString("\n", f);