Fix memory leak in add_subclass() found by NealN with valgrind.
Will backport.
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index ed5b829..cc60d6c 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2468,8 +2468,11 @@
while (--i >= 0) {
ref = PyList_GET_ITEM(list, i);
assert(PyWeakref_CheckRef(ref));
- if (PyWeakref_GET_OBJECT(ref) == Py_None)
- return PyList_SetItem(list, i, new);
+ if (PyWeakref_GET_OBJECT(ref) == Py_None) {
+ i = PyList_SetItem(list, i, new);
+ Py_DECREF(new);
+ return i;
+ }
}
i = PyList_Append(list, new);
Py_DECREF(new);