summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-28 00:03:54 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-28 00:03:54 (GMT)
commit855d9a985b861cc2c475f4020c120a25548b4c98 (patch)
treeca5579e812c9f1c00aec35f088f0348143399419 /Modules
parent630e5355b5cf25cc5a3b1a939d409fddfef59c8a (diff)
downloadcpython-855d9a985b861cc2c475f4020c120a25548b4c98.zip
cpython-855d9a985b861cc2c475f4020c120a25548b4c98.tar.gz
cpython-855d9a985b861cc2c475f4020c120a25548b4c98.tar.bz2
Plug a leak and beef-up test coverage.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_heapqmodule.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index 192e843..5a78c45 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;
}