]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` (#151127)
authorsobolevn <mail@sobolevn.me>
Tue, 9 Jun 2026 10:03:33 +0000 (13:03 +0300)
committerGitHub <noreply@github.com>
Tue, 9 Jun 2026 10:03:33 +0000 (10:03 +0000)
Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst [new file with mode: 0644]
Python/flowgraph.c

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 (file)
index 0000000..3f699a5
--- /dev/null
@@ -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`.
index eb0faf8cd183885cc83349f0c3e1f22ce1b73807..324a4fc1f10a68ec629273e2156cdb46d1d71ebe 100644 (file)
@@ -3279,6 +3279,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++) {
@@ -3331,6 +3332,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++) {