]> granicus.if.org Git - python/commitdiff
Repair refcounting on error return from type_set_bases.
authorMichael W. Hudson <mwh@python.net>
Thu, 7 Aug 2003 14:58:10 +0000 (14:58 +0000)
committerMichael W. Hudson <mwh@python.net>
Thu, 7 Aug 2003 14:58:10 +0000 (14:58 +0000)
Include a test case that failed for one of my efforts to repair this.

Lib/test/test_descr.py
Objects/typeobject.c

index cb13ff2e065a926a8d24a11a9d796124bd9e7564..b3336d1fc8d784f53714dee8cc0c4395caff28eb 100644 (file)
@@ -3585,6 +3585,13 @@ def test_mutable_bases():
         # actually, we'll have crashed by here...
         raise TestFailed, "shouldn't be able to create inheritance cycles"
 
+    try:
+        D.__bases__ = (C, C)
+    except TypeError:
+        pass
+    else:
+        raise TestFailed, "didn't detect repeated base classes"
+
     try:
         D.__bases__ = (E,)
     except TypeError:
index 60c4fbc6d10d56aaefbcd4405cfc231b5332bbe1..2a7df8aa6326ad7e6462dbe0c1a9d60efcfffb99 100644 (file)
@@ -303,13 +303,16 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
        return r;
 
   bail:
+       Py_DECREF(type->tp_bases);
+       Py_DECREF(type->tp_base);
+       if (type->tp_mro != old_mro) {
+               Py_DECREF(type->tp_mro);
+       }
+
        type->tp_bases = old_bases;
        type->tp_base = old_base;
        type->tp_mro = old_mro;
 
-       Py_DECREF(value);
-       Py_DECREF(new_base);
-
        return -1;
 }