From 855d9a985b861cc2c475f4020c120a25548b4c98 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Tue, 28 Sep 2004 00:03:54 +0000 Subject: Plug a leak and beef-up test coverage. --- Modules/_heapqmodule.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'Modules/_heapqmodule.c') diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index 192e843690..5a78c453e1 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -28,8 +28,10 @@ _siftdown(PyListObject *heap, int startpos, int pos) parentpos = (pos - 1) >> 1; parent = PyList_GET_ITEM(heap, parentpos); cmp = PyObject_RichCompareBool(parent, newitem, Py_LE); - if (cmp == -1) + if (cmp == -1) { + Py_DECREF(newitem); return -1; + } if (cmp == 1) break; Py_INCREF(parent); @@ -69,8 +71,10 @@ _siftup(PyListObject *heap, int pos) PyList_GET_ITEM(heap, rightpos), PyList_GET_ITEM(heap, childpos), Py_LE); - if (cmp == -1) + if (cmp == -1) { + Py_DECREF(newitem); return -1; + } if (cmp == 1) childpos = rightpos; } @@ -315,8 +319,10 @@ _siftdownmax(PyListObject *heap, int startpos, int pos) parentpos = (pos - 1) >> 1; parent = PyList_GET_ITEM(heap, parentpos); cmp = PyObject_RichCompareBool(newitem, parent, Py_LE); - if (cmp == -1) + if (cmp == -1) { + Py_DECREF(newitem); return -1; + } if (cmp == 1) break; Py_INCREF(parent); @@ -356,8 +362,10 @@ _siftupmax(PyListObject *heap, int pos) PyList_GET_ITEM(heap, childpos), PyList_GET_ITEM(heap, rightpos), Py_LE); - if (cmp == -1) + if (cmp == -1) { + Py_DECREF(newitem); return -1; + } if (cmp == 1) childpos = rightpos; } -- cgit v1.2.1