From: Guido van Rossum Date: Fri, 18 Oct 2002 13:42:21 +0000 (+0000) Subject: Backport of 2.183: X-Git-Tag: v2.2.3c1~295 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3cdc2c6de226fa8a1c04cb00294809548ce065ba;p=thirdparty%2FPython%2Fcpython.git Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind. --- diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 8a1adc914594..2427c4e24ab7 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2249,8 +2249,11 @@ add_subclass(PyTypeObject *base, PyTypeObject *type) 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);