diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-07-08 22:32:04 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-07-08 22:32:04 (GMT) |
commit | e0af3a802a67d3467b18510869ee1cf9d233fe8e (patch) | |
tree | bbcb6621d32461db6fac11ae277b5fa3f74b5617 /Python/peephole.c | |
parent | bf2e2f9bdf3366abf6004cad2cc46782d8b31367 (diff) | |
download | cpython-e0af3a802a67d3467b18510869ee1cf9d233fe8e.zip cpython-e0af3a802a67d3467b18510869ee1cf9d233fe8e.tar.gz cpython-e0af3a802a67d3467b18510869ee1cf9d233fe8e.tar.bz2 |
Issue #18408: Fix PyCode_Optimize(): raise a MemoryError on memory allocation
failure.
Diffstat (limited to 'Python/peephole.c')
-rw-r--r-- | Python/peephole.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/peephole.c b/Python/peephole.c index e6877bb..a49790a 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -381,8 +381,10 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, /* Make a modifiable copy of the code string */ codestr = (unsigned char *)PyMem_Malloc(codelen); - if (codestr == NULL) + if (codestr == NULL) { + PyErr_NoMemory(); goto exitError; + } codestr = (unsigned char *)memcpy(codestr, PyBytes_AS_STRING(code), codelen); @@ -396,8 +398,10 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, /* Mapping to new jump targets after NOPs are removed */ addrmap = (int *)PyMem_Malloc(codelen * sizeof(int)); - if (addrmap == NULL) + if (addrmap == NULL) { + PyErr_NoMemory(); goto exitError; + } blocks = markblocks(codestr, codelen); if (blocks == NULL) |