diff Objects/typeobject.c @ 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 e374ea7ac4ce
children eea40c417205
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);