Kaydet (Commit) c9f510ae authored tarafından Michael W. Hudson's avatar Michael W. Hudson

Any call to insort_{left,right} with a non-list leaked a reference to None

(or to whatever the 'insert' method chose to return).
üst f8df9a89
...@@ -65,7 +65,7 @@ slice of a to be searched.\n"); ...@@ -65,7 +65,7 @@ slice of a to be searched.\n");
static PyObject * static PyObject *
insort_right(PyObject *self, PyObject *args) insort_right(PyObject *self, PyObject *args)
{ {
PyObject *list, *item; PyObject *list, *item, *result;
int lo = 0; int lo = 0;
int hi = -1; int hi = -1;
int index; int index;
...@@ -80,9 +80,11 @@ insort_right(PyObject *self, PyObject *args) ...@@ -80,9 +80,11 @@ insort_right(PyObject *self, PyObject *args)
if (PyList_Insert(list, index, item) < 0) if (PyList_Insert(list, index, item) < 0)
return NULL; return NULL;
} else { } else {
if (PyObject_CallMethod(list, "insert", "iO", index, item) result = PyObject_CallMethod(list, "insert", "iO",
== NULL) index, item);
if (result == NULL)
return NULL; return NULL;
Py_DECREF(result);
} }
Py_RETURN_NONE; Py_RETURN_NONE;
...@@ -158,7 +160,7 @@ slice of a to be searched.\n"); ...@@ -158,7 +160,7 @@ slice of a to be searched.\n");
static PyObject * static PyObject *
insort_left(PyObject *self, PyObject *args) insort_left(PyObject *self, PyObject *args)
{ {
PyObject *list, *item; PyObject *list, *item, *result;
int lo = 0; int lo = 0;
int hi = -1; int hi = -1;
int index; int index;
...@@ -173,9 +175,11 @@ insort_left(PyObject *self, PyObject *args) ...@@ -173,9 +175,11 @@ insort_left(PyObject *self, PyObject *args)
if (PyList_Insert(list, index, item) < 0) if (PyList_Insert(list, index, item) < 0)
return NULL; return NULL;
} else { } else {
if (PyObject_CallMethod(list, "insert", "iO", index, item) result = PyObject_CallMethod(list, "insert", "iO",
== NULL) index, item);
if (result == NULL)
return NULL; return NULL;
Py_DECREF(result);
} }
Py_RETURN_NONE; Py_RETURN_NONE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment