From 23b35a55291ec9a94bb18d211d80d47e0963b476 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 9 Jun 2026 09:38:42 +0300 Subject: [PATCH 1/4] gh-151126: Fix missing `PyErr_NoMemory()` in `remove_unused_consts` --- Python/flowgraph.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/flowgraph.c b/Python/flowgraph.c index eb0faf8cd183885..e128674ba66d219 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -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++) { From d969e4fc4fa01a86e9c68c7137bc91714218d76d Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 9 Jun 2026 10:25:58 +0300 Subject: [PATCH 2/4] Address review --- Python/flowgraph.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/flowgraph.c b/Python/flowgraph.c index e128674ba66d219..324a4fc1f10a68e 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -3332,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++) { From 09bb0fc131c5175646a96d6cee3b1378ddb5c6f5 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 9 Jun 2026 10:28:37 +0300 Subject: [PATCH 3/4] Add NEWS --- .../2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst 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 000000000000000..d572c3e8ee7a557 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst @@ -0,0 +1 @@ +Add missing :c:func:`PyErr_NoMemory` call to ``Python/flowgraph.c`` module. From 1cfa4b9b95df301e8a15eb6f32a0bccbea6d2322 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 9 Jun 2026 12:33:26 +0300 Subject: [PATCH 4/4] Fix NEWS wording --- .../2026-06-09-10-28-30.gh-issue-151126.DKa6Sl.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 index d572c3e8ee7a557..3f699a50d7a42bb 100644 --- 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 @@ -1 +1,3 @@ -Add missing :c:func:`PyErr_NoMemory` call to ``Python/flowgraph.c`` module. +Fix a crash, when there's no memory left on a device, +which happened in code compilation. +Now it raises a proper :exc:`MemoryError`.