Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e0af3a8

Browse files
committed
Issue #18408: Fix PyCode_Optimize(): raise a MemoryError on memory allocation
failure.
1 parent bf2e2f9 commit e0af3a8

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Python/peephole.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,10 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
381381

382382
/* Make a modifiable copy of the code string */
383383
codestr = (unsigned char *)PyMem_Malloc(codelen);
384-
if (codestr == NULL)
384+
if (codestr == NULL) {
385+
PyErr_NoMemory();
385386
goto exitError;
387+
}
386388
codestr = (unsigned char *)memcpy(codestr,
387389
PyBytes_AS_STRING(code), codelen);
388390

@@ -396,8 +398,10 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
396398

397399
/* Mapping to new jump targets after NOPs are removed */
398400
addrmap = (int *)PyMem_Malloc(codelen * sizeof(int));
399-
if (addrmap == NULL)
401+
if (addrmap == NULL) {
402+
PyErr_NoMemory();
400403
goto exitError;
404+
}
401405

402406
blocks = markblocks(codestr, codelen);
403407
if (blocks == NULL)

0 commit comments

Comments
 (0)