diff Modules/_bisectmodule.c @ 32898:daec2d311def legacy-trunk

Any call to insort_{left,right} with a non-list leaked a reference to None (or to whatever the 'insert' method chose to return).
author Michael W. Hudson <mwh@python.net>
date Mon, 02 Aug 2004 13:24:54 +0000
parents ed20259a1ea5
children 3572249c1e77
line wrap: on
line diff
--- a/Modules/_bisectmodule.c	Mon Aug 02 13:22:01 2004 +0000
+++ b/Modules/_bisectmodule.c	Mon Aug 02 13:24:54 2004 +0000
@@ -65,7 +65,7 @@
 static PyObject *
 insort_right(PyObject *self, PyObject *args)
 {
-	PyObject *list, *item;
+	PyObject *list, *item, *result;
 	int lo = 0;
 	int hi = -1;
 	int index;
@@ -80,9 +80,11 @@
 		if (PyList_Insert(list, index, item) < 0)
 			return NULL;
 	} else {
-		if (PyObject_CallMethod(list, "insert", "iO", index, item)
-			== NULL)
+		result = PyObject_CallMethod(list, "insert", "iO",
+					     index, item);
+		if (result == NULL)
 			return NULL;
+		Py_DECREF(result);
 	}
 
 	Py_RETURN_NONE;
@@ -158,7 +160,7 @@
 static PyObject *
 insort_left(PyObject *self, PyObject *args)
 {
-	PyObject *list, *item;
+	PyObject *list, *item, *result;
 	int lo = 0;
 	int hi = -1;
 	int index;
@@ -173,9 +175,11 @@
 		if (PyList_Insert(list, index, item) < 0)
 			return NULL;
 	} else {
-		if (PyObject_CallMethod(list, "insert", "iO", index, item)
-			== NULL)
+		result = PyObject_CallMethod(list, "insert", "iO",
+					     index, item);
+		if (result == NULL)
 			return NULL;
+		Py_DECREF(result);
 	}
 
 	Py_RETURN_NONE;