From e723e453a1f11f4865f25d93d3cf20280d9f831a Mon Sep 17 00:00:00 2001 From: "Michael W. Hudson" Date: Thu, 7 Aug 2003 14:58:10 +0000 Subject: Repair refcounting on error return from type_set_bases. Include a test case that failed for one of my efforts to repair this. --- Lib/test/test_descr.py | 7 +++++++ Objects/typeobject.c | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index cb13ff2..b3336d1 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -3586,6 +3586,13 @@ def test_mutable_bases(): 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: pass diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 60c4fbc..2a7df8a 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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; } -- cgit v0.12