Repository navigation
Many places have missing PyErr_NoMemory() call after failing memory allocation #151126
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Activity
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on Jun 9, 2026 Well, actually a lot of places have the same problem. I will turn this issue into a meta one and will 1 PR per module, so it would be easier to review / backport.
Reacted by Victor Stinner and Arseniy Terekhin- changed the title
[-]`remove_unused_consts` is missing `PyErr_NoMemory()` call[/-][+]Many places have missing `PyErr_NoMemory()` call after failing memory allocation[/+]on Jun 9, 2026 This is probably a new code. Such errors were fixed in old code years ago.
- added 8 commits that reference this issue
on Jun 9, 2026 37 remaining items
- added 5 commits that reference this issue
on Jun 27, 2026 - added a commit that references this issue
on Jul 1, 2026 - added a commit that references this issue
on Jul 15, 2026
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Projects
- StatusShow more project fieldsNo status
Crash report
remove_unused_constsinPython/flowgraph.cWhen
PyMem_Malloc(nconsts * sizeof(Py_ssize_t));fails, we need to set an exception.cpython/Python/flowgraph.c
Lines 3267 to 3283 in 29a920e
gethandlelistandgetattributelistin_winapi.cThis place misses it:
cpython/Modules/_winapi.c
Lines 1196 to 1198 in 9fdbade
All other error paths set exceptions, except this
if:cpython/Modules/_winapi.c
Lines 1278 to 1282 in 9fdbade
_channelends_newinModules/_interpchannelsmodule.ccpython/Modules/_interpchannelsmodule.c
Lines 920 to 926 in 3ca93ab
Later we check for errors in
handle_channel_error, it requires either settingerrto non-1or to set Python exception. Both are false, it fails with the assertion failure.Linked PRs
PyErr_NoMemory()inremove_unused_consts#151127PyErr_NoMemory()inremove_unused_consts(GH-151127) #151134PyErr_NoMemory()inremove_unused_consts(GH-151127) #151135PyErr_NoMemory()inremove_unused_consts(GH-151127) #151136PyErr_NoMemory()instrong_cache_node_new#151137PyErr_NoMemoryin_winapimodule #151154PyErr_NoMemoryin_winapimodule (GH-151154) #151180PyErr_NoMemoryin_winapimodule (GH-151154) #151181PyErr_NoMemoryin_winapimodule (GH-151154) #151182_interpchannelsmodule.c#151239_interpchannelsmodule.c(GH-151239) #151265_interpchannelsmodule.c(GH-151239) #151266_interpchannelsmodule.c(GH-151239) #151336_interpchannelsmodule.c(GH-151239) #151338os._path_splitroot#151339os._path_splitroot(GH-151339) #151360os._path_splitroot(GH-151339) #151361os._path_splitroot(GH-151339) #151362ctypes.get_errno#151382ctypes.get_errno(GH-151382) #151398ctypes.get_errno(GH-151382) #151399ctypes.get_errno(GH-151382) #151400PyErr_NoMemoryinfileutils.c#151580PyErr_NoMemoryintypeobject.c#151582PyErr_NoMemoryin_winapi.c#151588PyErr_NoMemoryingetpath.c#151590PyErr_NoMemory()intype_from_slots_or_spec(GH-151582) #152014PyErr_NoMemory()intype_from_slots_or_spec(GH-151582) #152015PyErr_NoMemory()intype_from_slots_or_spec(GH-151582) #152016_interpretersmodule.c(GH-151624) #152169_interpretersmodule.c(GH-151624) #152170PyErr_NoMemoryintestinternalcapi.c#152177PyErr_NoMemoryintestinternalcapi.c(GH-152177) #152179PyErr_NoMemoryintestinternalcapi.c(GH-152177) #152180PyErr_NoMemoryintestinternalcapi.c(GH-152177) #152181PyErr_NoMemoryin_winapi.c(GH-151588) #152182PyErr_NoMemoryin_winapi.c(GH-151588) #152183PyErr_NoMemoryin_winapi.c(GH-151588) #152184tkinterandsocketmodules initializations #152418tkinterandsocketmodules initializations (GH-152418) #152420tkinterandsocketmodules initializations (GH-152418) #152421tkinterandsocketmodules initializations (GH-152418) #152422Py_STACKREF_DEBUG#152478Py_STACKREF_DEBUG(GH-152478) #152677Py_STACKREF_DEBUG(GH-152478) #152678PyErr_NoMemoryerrors in_ctypes.c#152720PyErr_NoMemoryerrors in_ctypes.c(GH-152720) #153708PyErr_NoMemoryerrors in_ctypes.c(GH-152720) #153709PyErr_NoMemoryerrors in_ctypes.c(GH-152720) #153710_interpretersmodule.c#153765MemoryErroron allocation failure in CJK codec macros #156292strdupresult in readlineon_completion#156299MemoryErroron alloc failure in_PyXIData_InitWithSize#156301