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

Skip to content

Commit e723e45

Browse files
author
Michael W. Hudson
committed
Repair refcounting on error return from type_set_bases.
Include a test case that failed for one of my efforts to repair this.
1 parent bb18f62 commit e723e45

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lib/test/test_descr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,6 +3585,13 @@ class L(list):
35853585
# actually, we'll have crashed by here...
35863586
raise TestFailed, "shouldn't be able to create inheritance cycles"
35873587

3588+
try:
3589+
D.__bases__ = (C, C)
3590+
except TypeError:
3591+
pass
3592+
else:
3593+
raise TestFailed, "didn't detect repeated base classes"
3594+
35883595
try:
35893596
D.__bases__ = (E,)
35903597
except TypeError:

Objects/typeobject.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,16 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
303303
return r;
304304

305305
bail:
306+
Py_DECREF(type->tp_bases);
307+
Py_DECREF(type->tp_base);
308+
if (type->tp_mro != old_mro) {
309+
Py_DECREF(type->tp_mro);
310+
}
311+
306312
type->tp_bases = old_bases;
307313
type->tp_base = old_base;
308314
type->tp_mro = old_mro;
309315

310-
Py_DECREF(value);
311-
Py_DECREF(new_base);
312-
313316
return -1;
314317
}
315318

0 commit comments

Comments
 (0)