You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is wrong with the current code? If an allocation fails due to lack of memory (a very rare almost non-existent event), then an alternate path is taken that does not require additional memory.
AFAICT this is a false positive from the umbrella issue.
AFAICT this is a false positive from the umbrella issue.
There is a real error here that the reproducer catches. However, the umbrella issue gives the wrong explanation. The problem has nothing to do with deque.copy but deque.copy is one execution path for the error.
Reproducer (for reference)
import_testcapifromcollectionsimportdequeforninrange(1, 80):
d=deque(range(200))
_testcapi.set_nomemory(n, 0)
try:
d2=d.copy()
_testcapi.remove_mem_hooks()
breakexceptMemoryError:
_testcapi.remove_mem_hooks()
except:
_testcapi.remove_mem_hooks()
# Fatal: _Py_Dealloc: Deallocator of type 'collections.deque' cleared
The real problem is that this debug check in _Py_Dealloc fails:
Thus, in the case of OOM, Py_DECREF(new_deque) is called with an exception already set.
In order to free the memory, eventually deque_clear is called. deque_clear calls newblock, which in the case of OOM, replaces the current exception with a new PyErr_NoMemory(). Then, deque_clear calls PyErr_Clear(), meaning that there are now no exceptions despite deque_append_lock_held originally setting one:
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y
~ # /pfm/tools/mem_limit_exec /pfm/py/bin/python3 /pfm/scratch/reproducers/t1-1.
min.py
Fatal Python error: _Py_Dealloc: Deallocator of type 'collections.deque' cleared the current exception
Python runtime state: initialized
Current thread 0x0000fffff7fee020 [python3] (most recent call first):
File "<input-53>", line 2 in <module>
File "/pfm/scratch/reproducers/t1-1.min.py", line 10 in <module>
Aborted
~ # /pfm/tools/mem_limit_exec /pfm/py/bin/python3 /pfm/scratch/reproducers/t1-1.
min.py
Fatal Python error: _Py_Dealloc: Deallocator of type 'collections.deque' cleared the current exception
Python runtime state: initialized
Current thread 0x0000fffff7fee020 [python3] (most recent call first):
File "<input-53>", line 2 in <module>
File "/pfm/scratch/reproducers/t1-1.min.py", line 10 in <module>
Aborted
~ #
Python 3.16.0a0 (heads/main-dirty:f8514dc, Jul 2 2026, 09:14:40) [Clang 22.1.6 ]
Activity
[-]'deque_clear' clears `MemoryError`[/-][+]`deque_clear` clears `MemoryError`[/+]rhettinger commentedon Jun 26, 2026
What is wrong with the current code? If an allocation fails due to lack of memory (a very rare almost non-existent event), then an alternate path is taken that does not require additional memory.
AFAICT this is a false positive from the umbrella issue.
brijkapadia commentedon Jun 27, 2026
There is a real error here that the reproducer catches. However, the umbrella issue gives the wrong explanation. The problem has nothing to do with
deque.copybutdeque.copyis one execution path for the error.Reproducer (for reference)
The real problem is that this debug check in
_Py_Deallocfails:Debug Check
cpython/Objects/object.c
Lines 3321 to 3342 in 1812162
For the specific case of the reproducer,
deque_copy_implcallsdeque_append_lock_heldand in the case of an error, callsPy_DECREF(new_deque):cpython/Modules/_collectionsmodule.c
Lines 634 to 638 in 1812162
Furthermore,
deque_append_lock_heldcallsnewblockwhich raises aPyErr_NoMemory()in the case of OOM:cpython/Modules/_collectionsmodule.c
Line 187 in 1812162
Thus, in the case of OOM,
Py_DECREF(new_deque)is called with an exception already set.In order to free the memory, eventually
deque_clearis called.deque_clearcallsnewblock, which in the case of OOM, replaces the current exception with a newPyErr_NoMemory(). Then,deque_clearcallsPyErr_Clear(), meaning that there are now no exceptions despitedeque_append_lock_heldoriginally setting one:cpython/Modules/_collectionsmodule.c
Lines 749 to 753 in 1812162
In debug builds, this is caught in
_Py_Dealloc,cpython/Objects/object.c
Lines 3329 to 3331 in 1812162
which gives the error
Fatal: _Py_Dealloc: Deallocator of type 'collections.deque' cleared the current exception.stestagg commentedon Jul 2, 2026
EDIT: ignore my previous, it was something else.
I just came across this in fuzzing, the following code reliably aborts for me:
gives (in linux with 2gb ram)