GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Many places have missing `PyErr_NoMemory()` call after failing memory allocation · Issue #151126 · python/cpython

Many places have missing PyErr_NoMemory() call after failing memory allocation #151126

New issue
Copy link
New issue
Copy link
Open
Open
Many places have missing PyErr_NoMemory() call after failing memory allocation#151126
Copy link
Assignees
sobolevn
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

@sobolevn
sobolevn
opened on Jun 9, 2026
Issue body actions

Crash report

  1. remove_unused_consts in Python/flowgraph.c

When PyMem_Malloc(nconsts * sizeof(Py_ssize_t)); fails, we need to set an exception.

cpython/Python/flowgraph.c

Lines 3267 to 3283 in 29a920e

static int
remove_unused_consts(basicblock *entryblock, PyObject *consts)
{
assert(PyList_CheckExact(consts));
Py_ssize_t nconsts = PyList_GET_SIZE(consts);
if (nconsts == 0) {
return SUCCESS; /* nothing to do */
}
Py_ssize_t *index_map = NULL;
Py_ssize_t *reverse_index_map = NULL;
int err = ERROR;
index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
if (index_map == NULL) {
goto end;
}

  1. gethandlelist and getattributelist in _winapi.c

This place misses it:

cpython/Modules/_winapi.c

Lines 1196 to 1198 in 9fdbade

ret = PyMem_Malloc(*size);
if (ret == NULL)
goto cleanup;

All other error paths set exceptions, except this if:

cpython/Modules/_winapi.c

Lines 1278 to 1282 in 9fdbade

attribute_list->attribute_list = PyMem_Malloc(attribute_list_size);
if (attribute_list->attribute_list == NULL) {
ret = -1;
goto cleanup;
}

  1. _channelends_new in Modules/_interpchannelsmodule.c

cpython/Modules/_interpchannelsmodule.c

Lines 920 to 926 in 3ca93ab

static _channelends *
_channelends_new(void)
{
_channelends *ends = GLOBAL_MALLOC(_channelends);
if (ends== NULL) {
return NULL;
}

Later we check for errors in handle_channel_error, it requires either setting err to non -1 or to set Python exception. Both are false, it fails with the assertion failure.

Linked PRs

  • gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts #151127
  • [3.15] gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (GH-151127) #151134
  • [3.14] gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (GH-151127) #151135
  • [3.13] gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (GH-151127) #151136
  • gh-151126: Add PyErr_NoMemory() in strong_cache_node_new #151137
  • gh-151126: Add missing PyErr_NoMemory in _winapi module #151154
  • [3.15] gh-151126: Add missing PyErr_NoMemory in _winapi module (GH-151154) #151180
  • [3.14] gh-151126: Add missing PyErr_NoMemory in _winapi module (GH-151154) #151181
  • [3.13] gh-151126: Add missing PyErr_NoMemory in _winapi module (GH-151154) #151182
  • gh-151126: Fix missing memory errors in _interpchannelsmodule.c #151239
  • [3.15] gh-151126: Fix missing memory errors in _interpchannelsmodule.c (GH-151239) #151265
  • [3.13] gh-151126: Fix missing memory errors in _interpchannelsmodule.c (GH-151239) #151266
  • [3.14] gh-151126: Fix missing memory errors in _interpchannelsmodule.c (GH-151239) #151336
  • [3.13] gh-151126: Fix missing memory errors in _interpchannelsmodule.c (GH-151239) #151338
  • gh-151126: Fix missing memory error in os._path_splitroot #151339
  • [3.15] gh-151126: Fix missing memory error in os._path_splitroot (GH-151339) #151360
  • [3.14] gh-151126: Fix missing memory error in os._path_splitroot (GH-151339) #151361
  • [3.13] gh-151126: Fix missing memory error in os._path_splitroot (GH-151339) #151362
  • gh-151126: Fix crash on unset memory error in ctypes.get_errno #151382
  • [3.15] gh-151126: Fix crash on unset memory error in ctypes.get_errno (GH-151382) #151398
  • [3.14] gh-151126: Fix crash on unset memory error in ctypes.get_errno (GH-151382) #151399
  • [3.13] gh-151126: Fix crash on unset memory error in ctypes.get_errno (GH-151382) #151400
  • gh-151126: Fix missing PyErr_NoMemory in fileutils.c #151580
  • gh-151126: Fix missing PyErr_NoMemory in typeobject.c #151582
  • gh-151126: Add missing PyErr_NoMemory in _winapi.c #151588
  • gh-151126: Fix missing PyErr_NoMemory in getpath.c #151590
  • gh-151126:Fix missing memory errors in _interpretersmodule.c #151624
  • gh-151126: Fix missing memory errors in _interpqueuesmodule.c #151639
  • [3.13] gh-151126: Add missing PyErr_NoMemory() in type_from_slots_or_spec (GH-151582) #152014
  • [3.14] gh-151126: Add missing PyErr_NoMemory() in type_from_slots_or_spec (GH-151582) #152015
  • [3.15] gh-151126: Add missing PyErr_NoMemory() in type_from_slots_or_spec (GH-151582) #152016
  • [3.15] gh-151126: Fix missing memory errors in _interpretersmodule.c (GH-151624) #152169
  • [3.14] gh-151126: Fix missing memory errors in _interpretersmodule.c (GH-151624) #152170
  • gh-151126: Fix missing PyErr_NoMemory in testinternalcapi.c #152177
  • [3.15] gh-151126: Fix missing PyErr_NoMemory in testinternalcapi.c (GH-152177) #152179
  • [3.14] gh-151126: Fix missing PyErr_NoMemory in testinternalcapi.c (GH-152177) #152180
  • [3.13] gh-151126: Fix missing PyErr_NoMemory in testinternalcapi.c (GH-152177) #152181
  • [3.15] gh-151126: Add missing PyErr_NoMemory in _winapi.c (GH-151588) #152182
  • [3.14] gh-151126: Add missing PyErr_NoMemory in _winapi.c (GH-151588) #152183
  • [3.13] gh-151126: Add missing PyErr_NoMemory in _winapi.c (GH-151588) #152184
  • gh-151126: Sets missing exceptions in tkinter and socket modules initializations #152418
  • [3.15] gh-151126: Sets missing exceptions in tkinter and socket modules initializations (GH-152418) #152420
  • [3.14] gh-151126: Sets missing exceptions in tkinter and socket modules initializations (GH-152418) #152421
  • [3.13] gh-151126: Sets missing exceptions in tkinter and socket modules initializations (GH-152418) #152422
  • gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG #152478
  • [3.15] gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG (GH-152478) #152677
  • [3.14] gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG (GH-152478) #152678
  • gh-151126: Fix PyErr_NoMemory errors in _ctypes.c  #152720
  • gh-151126: Set MemoryError in test C API allocation failures #153215
  • [3.13] gh-151126: Fix PyErr_NoMemory errors in _ctypes.c (GH-152720) #153708
  • [3.14] gh-151126: Fix PyErr_NoMemory errors in _ctypes.c (GH-152720) #153709
  • [3.15] gh-151126: Fix PyErr_NoMemory errors in _ctypes.c (GH-152720) #153710
  • [3.13] gh-151126: Fix missing memory errors in _interpretersmodule.c  #153765
  • gh-151126: set MemoryError on allocation failure in CJK codec macros #156292
  • gh-151126: Check strdup result in readline on_completion #156299
  • gh-151126: set MemoryError on alloc failure in _PyXIData_InitWithSize #156301
  • [3.14] gh-151126: Set MemoryError on allocation failure in CJK codec macros (GH-156292) #160673
  • [3.15] gh-151126: Set MemoryError on allocation failure in CJK codec macros (GH-156292) #160674
  • [3.15] gh-151126: set MemoryError on alloc failure in _PyXIData_InitWithSize (GH-156301) #161905
  • [3.14] gh-151126: set MemoryError on alloc failure in _PyXIData_InitWithSize (GH-156301) #161906

Activity

Next
  1. sobolevn
    self-assigned this
    on Jun 9, 2026
  2. sobolevn
    added
    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
    on Jun 9, 2026
  3. sobolevn commented on Jun 9, 2026

    @sobolevn
    sobolevn
    on Jun 9, 2026
    MemberAuthor
    More actions

    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
  4. sobolevn
    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
  5. StanFromIreland
    added this to Date and time issues 🕰️on Jun 9, 2026
  6. serhiy-storchaka commented on Jun 9, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 9, 2026
    Member
    More actions

    This is probably a new code. Such errors were fixed in old code years ago.

  7. sobolevn
    added 8 commits that reference this issue on Jun 9, 2026

    gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` (#…

    3186547

    pythongh-151126: Add `PyErr_NoMemory()` in `strong_cache_node_new`

    65eebcf

    [3.13] gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_co…

    140af0f

    [3.15] gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_co…

    8a2bf2a

    [3.14] gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_co…

    5c6402e

    gh-151126: Add missing `PyErr_NoMemory` in `_winapi` module (#151154)

    8d94fa7

    [3.14] gh-151126: Add missing `PyErr_NoMemory` in `_winapi` module (G…

    a33c6a1

    [3.13] gh-151126: Add missing `PyErr_NoMemory` in `_winapi` module (G…

    0488451
  8. 44 remaining items

  9. pyctrl
    added a commit that references this issue on Jul 5, 2026

    pythongh-151126: Add missing `PyErr_NoMemory()` in `type_from_slots_o…

    0b25972
  10. kumaraditya303
    added a commit that references this issue on Jul 14, 2026

    gh-151126: Fix `PyErr_NoMemory` errors in `_ctypes.c` (#152720)

    d807210
  11. sobolevn
    added a commit that references this issue on Jul 15, 2026

    [3.13] gh-151126: Fix missing memory errors in `_interpretersmodule.c` (

    8010bf0
  12. Yhg1s
    added a commit that references this issue on Aug 4, 2026

    [3.13] gh-151126: Fix `PyErr_NoMemory` errors in `_ctypes.c` (GH-152720…

    3c431d5
  13. KowalskiThomas
    added 3 commits that reference this issue on Aug 23, 2026

    pythongh-151126: Set MemoryError on alloc failure in CJK codec macros

    6ae41c8

    pythongh-151126: Check strdup result in readline on_completion

    7c08f01

    pythongh-151126: Set MemoryError on alloc failure in _PyXIData_InitWi…

    8cf9517
  14. encukou
    added a commit that references this issue on Oct 9, 2026

    [3.15] gh-151126: Fix `PyErr_NoMemory` errors in `_ctypes.c` (GH-152720…

    bb5ff8c
  15. StanFromIreland
    added 3 commits that reference this issue on Oct 25, 2026

    gh-151126: Set `MemoryError` on allocation failure in CJK codec macros (

    d441a11

    [3.14] gh-151126: Set `MemoryError` on allocation failure in CJK code…

    a5892db

    [3.15] gh-151126: Set `MemoryError` on allocation failure in CJK code…

    c6e7431
  16. sobolevn
    added a commit that references this issue on Nov 11, 2026

    [3.14] gh-151126: Fix `PyErr_NoMemory` errors in `_ctypes.c` (GH-152720…

    0df6b24
  17. cmaloney
    added 3 commits that reference this issue on Nov 12, 2026

    gh-151126: set `MemoryError` on alloc failure in `_PyXIData_InitWithS…

    a6018c5

    [3.15] gh-151126: set `MemoryError` on alloc failure in `_PyXIData_In…

    ef6437e

    [3.14] gh-151126: set `MemoryError` on alloc failure in `_PyXIData_In…

    5dedab8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @sobolevn
    sobolevn

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

  • Date and time issues 🕰️
    Status
    No status
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.