Skip to content

Commit 3186547

Browse files
authored
gh-151126: Fix missing PyErr_NoMemory() in remove_unused_consts (#151127)
1 parent 29a920e commit 3186547

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

32803280
index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
32813281
if (index_map == NULL) {
3282+
PyErr_NoMemory();
32823283
goto end;
32833284
}
32843285
for (Py_ssize_t i = 1; i < nconsts; i++) {
@@ -3331,6 +3332,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
33313332
/* adjust const indices in the bytecode */
33323333
reverse_index_map = PyMem_Malloc(nconsts * sizeof(Py_ssize_t));
33333334
if (reverse_index_map == NULL) {
3335+
PyErr_NoMemory();
33343336
goto end;
33353337
}
33363338
for (Py_ssize_t i = 0; i < nconsts; i++) {

0 commit comments

Comments
 (0)