]> granicus.if.org Git - python/commitdiff
Exception__str__(): In case 1, be sure to decref the tmp local
authorBarry Warsaw <barry@python.org>
Sun, 9 Jul 2000 22:27:10 +0000 (22:27 +0000)
committerBarry Warsaw <barry@python.org>
Sun, 9 Jul 2000 22:27:10 +0000 (22:27 +0000)
variable.  This crushes another memory leak.  Slight rewrite
included.

Python/exceptions.c

index c32e15ccbc5d6a661d8193f85e0946bf15e4bf2c..f766ba5ef34ddbb7742b940076a877dd7d9a247b 100644 (file)
@@ -231,7 +231,6 @@ static PyObject*
 Exception__str__(PyObject* self, PyObject* args)
 {
     PyObject* out;
-    PyObject* tmp;
 
     if (!PyArg_ParseTuple(args, "O", &self))
         return NULL;
@@ -245,11 +244,16 @@ Exception__str__(PyObject* self, PyObject* args)
         out = PyString_FromString("");
         break;
     case 1:
-       if (!(tmp = PySequence_GetItem(args, 0)))
-           out = NULL;
-       else
+    {
+       PyObject* tmp = PySequence_GetItem(args, 0);
+       if (tmp) {
            out = PyObject_Str(tmp);
+           Py_DECREF(tmp);
+       }
+       else
+           out = NULL;
        break;
+    }
     default:
         out = PyObject_Str(args);
         break;