https://github.com/python/cpython/commit/1aa1d76b7f2b5d4f767029d6d531f126e2857187
commit: 1aa1d76b7f2b5d4f767029d6d531f126e2857187
branch: main
author: Pieter Eendebak <[email protected]>
committer: vstinner <[email protected]>
date: 2026-03-04T23:45:43+01:00
summary:
gh-145376: Fix reference leaks in deque (#145421)
Fix a reference leak if newblock() fails in _collections.deque.
files:
M Modules/_collectionsmodule.c
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 72865f87fc484f..c3d63c8aab4b47 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -342,8 +342,10 @@ deque_append_lock_held(dequeobject *deque, PyObject *item,
Py_ssize_t maxlen)
{
if (deque->rightindex == BLOCKLEN - 1) {
block *b = newblock(deque);
- if (b == NULL)
+ if (b == NULL) {
+ Py_DECREF(item);
return -1;
+ }
b->leftlink = deque->rightblock;
CHECK_END(deque->rightblock->rightlink);
deque->rightblock->rightlink = b;
@@ -389,8 +391,10 @@ deque_appendleft_lock_held(dequeobject *deque, PyObject
*item,
{
if (deque->leftindex == 0) {
block *b = newblock(deque);
- if (b == NULL)
+ if (b == NULL) {
+ Py_DECREF(item);
return -1;
+ }
b->rightlink = deque->leftblock;
CHECK_END(deque->leftblock->leftlink);
deque->leftblock->leftlink = b;
@@ -564,7 +568,6 @@ deque_extendleft_impl(dequeobject *deque, PyObject
*iterable)
iternext = *Py_TYPE(it)->tp_iternext;
while ((item = iternext(it)) != NULL) {
if (deque_appendleft_lock_held(deque, item, maxlen) == -1) {
- Py_DECREF(item);
Py_DECREF(it);
return NULL;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]