Mercurial > cpython-lru_cache-weakref
changeset 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 035b8deb52c1 |
| children | eea40c417205 |
| files | Objects/typeobject.c |
| diffstat | 1 files changed, 5 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/Objects/typeobject.c Thu Oct 17 22:17:43 2002 +0000 +++ b/Objects/typeobject.c Fri Oct 18 13:42:21 2002 +0000 @@ -2249,8 +2249,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);
