]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of 2.183:
authorGuido van Rossum <guido@python.org>
Fri, 18 Oct 2002 13:42:21 +0000 (13:42 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 18 Oct 2002 13:42:21 +0000 (13:42 +0000)
Fix memory leak in add_subclass() found by NealN with valgrind.

Objects/typeobject.c

index 8a1adc914594d5345d4567d12c15f8fdfc67d5d8..2427c4e24ab7861e22cc9d345cb7db59a1842b74 100644 (file)
@@ -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);