Skip to content

Commit 5c6402e

Browse files
[3.14] gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (GH-151127) (#151135)
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 3ece6b5 commit 5c6402e

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
@@ -3185,6 +3185,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
31853185

31863186
index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
31873187
if (index_map == NULL) {
3188+
PyErr_NoMemory();
31883189
goto end;
31893190
}
31903191
for (Py_ssize_t i = 1; i < nconsts; i++) {
@@ -3237,6 +3238,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
32373238
/* adjust const indices in the bytecode */
32383239
reverse_index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
32393240
if (reverse_index_map == NULL) {
3241+
PyErr_NoMemory();
32403242
goto end;
32413243
}
32423244
for (Py_ssize_t i = 0; i < nconsts; i++) {

0 commit comments

Comments
 (0)