From bd4001fc4bd9d747dbbd89ea898bcb031bc82a20 Mon Sep 17 00:00:00 2001 From: Steve Stagg Date: Fri, 3 Jul 2026 14:45:45 +0100 Subject: [PATCH 1/2] remove redundant decref following allocation failure appending item to deque --- Modules/_collectionsmodule.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index e96a546a818d3d..62d1dad5735ec8 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -512,7 +512,6 @@ deque_extend_impl(dequeobject *deque, PyObject *iterable) iternext = *Py_TYPE(it)->tp_iternext; while ((item = iternext(it)) != NULL) { if (deque_append_lock_held(deque, item, maxlen) == -1) { - Py_DECREF(item); Py_DECREF(it); return NULL; } From b74e0df9116225506c534963861de6232c73dbf8 Mon Sep 17 00:00:00 2001 From: Steve Stagg Date: Fri, 3 Jul 2026 15:05:52 +0100 Subject: [PATCH 2/2] Add blurb --- .../next/Library/2026-07-03-14-54-33.gh-issue-152951.u8tPCI.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-03-14-54-33.gh-issue-152951.u8tPCI.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-03-14-54-33.gh-issue-152951.u8tPCI.rst b/Misc/NEWS.d/next/Library/2026-07-03-14-54-33.gh-issue-152951.u8tPCI.rst new file mode 100644 index 00000000000000..c3d56c6d59c91b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-03-14-54-33.gh-issue-152951.u8tPCI.rst @@ -0,0 +1,2 @@ +:class:`collections.deque` prevent rare crash when calling ``extend`` under +high memory pressure conditions.