From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 9 Jun 2026 10:27:34 +0000 (+0200) Subject: [3.13] gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` (GH-151127... X-Git-Tag: v3.13.14~21 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=140af0fd14241dead4918211e80306f5d8ea5486;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` (GH-151127) (#151136) gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` (GH-151127) (cherry picked from commit 3186547c1ec76e1afab82ec32271ec5b9467fdeb) Co-authored-by: sobolevn --- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst new file mode 100644 index 000000000000..3f699a50d7a4 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst @@ -0,0 +1,3 @@ +Fix a crash, when there's no memory left on a device, +which happened in code compilation. +Now it raises a proper :exc:`MemoryError`. diff --git a/Python/flowgraph.c b/Python/flowgraph.c index c1602918a041..baba1f75b9cd 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -2040,6 +2040,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts) index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t)); if (index_map == NULL) { + PyErr_NoMemory(); goto end; } for (Py_ssize_t i = 1; i < nconsts; i++) { @@ -2097,6 +2098,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts) /* adjust const indices in the bytecode */ reverse_index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t)); if (reverse_index_map == NULL) { + PyErr_NoMemory(); goto end; } for (Py_ssize_t i = 0; i < nconsts; i++) {