Skip to content

Commit 8a2bf2a

Browse files
[3.15] gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (GH-151127) (#151134)
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 83e26a4 commit 8a2bf2a

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

32743274
index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
32753275
if (index_map == NULL) {
3276+
PyErr_NoMemory();
32763277
goto end;
32773278
}
32783279
for (Py_ssize_t i = 1; i < nconsts; i++) {
@@ -3325,6 +3326,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
33253326
/* adjust const indices in the bytecode */
33263327
reverse_index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
33273328
if (reverse_index_map == NULL) {
3329+
PyErr_NoMemory();
33283330
goto end;
33293331
}
33303332
for (Py_ssize_t i = 0; i < nconsts; i++) {

0 commit comments

Comments
 (0)