Skip to content

Commit 140af0f

Browse files
[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 3186547) Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent c51354e commit 140af0f

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a crash, when there's no memory left on a device,
2+
which happened in code compilation.
3+
Now it raises a proper :exc:`MemoryError`.

Python/flowgraph.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
20402040

20412041
index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
20422042
if (index_map == NULL) {
2043+
PyErr_NoMemory();
20432044
goto end;
20442045
}
20452046
for (Py_ssize_t i = 1; i < nconsts; i++) {
@@ -2097,6 +2098,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
20972098
/* adjust const indices in the bytecode */
20982099
reverse_index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
20992100
if (reverse_index_map == NULL) {
2101+
PyErr_NoMemory();
21002102
goto end;
21012103
}
21022104
for (Py_ssize_t i = 0; i < nconsts; i++) {

0 commit comments

Comments
 (0)