]> granicus.if.org Git - python/commitdiff
Fix memory leak in add_subclass() found by NealN with valgrind.
authorGuido van Rossum <guido@python.org>
Fri, 18 Oct 2002 13:41:47 +0000 (13:41 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 18 Oct 2002 13:41:47 +0000 (13:41 +0000)
Will backport.

Objects/typeobject.c

index ed5b82951ae163eb000c3d2067dd7d571c701be9..cc60d6c6af732b5a9e9db5632bf6a971c9fd7a99 100644 (file)
@@ -2468,8 +2468,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);