Skip to content

Commit 764a46d

Browse files
committed
Issue #18408: Fix heapq.heappop(), handle PyList_SetSlice() failure
1 parent 2ff51b8 commit 764a46d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Modules/_heapqmodule.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ heappop(PyObject *self, PyObject *heap)
168168

169169
lastelt = PyList_GET_ITEM(heap, n-1) ;
170170
Py_INCREF(lastelt);
171-
PyList_SetSlice(heap, n-1, n, NULL);
171+
if (PyList_SetSlice(heap, n-1, n, NULL) < 0) {
172+
Py_DECREF(lastelt);
173+
return NULL;
174+
}
172175
n--;
173176

174177
if (!n)

0 commit comments

Comments
 (0)