]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Any call to insort_{left,right} with a non-list leaked a reference to None
authorMichael W. Hudson <mwh@python.net>
Mon, 2 Aug 2004 13:24:54 +0000 (13:24 +0000)
committerMichael W. Hudson <mwh@python.net>
Mon, 2 Aug 2004 13:24:54 +0000 (13:24 +0000)
(or to whatever the 'insert' method chose to return).

Modules/_bisectmodule.c

index d3361586488e809674f588593f641dc1a5f36a89..f4016fe9f68a96c90adf823001bdb39a1a3f3af5 100644 (file)
@@ -65,7 +65,7 @@ slice of a to be searched.\n");
 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 @@ insort_right(PyObject *self, PyObject *args)
                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 @@ slice of a to be searched.\n");
 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 @@ insort_left(PyObject *self, PyObject *args)
                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;