mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Issue #18408: Fix PyCode_Optimize(): raise a MemoryError on memory allocation
failure.
This commit is contained in:
parent
bf2e2f9bdf
commit
e0af3a802a
1 changed files with 6 additions and 2 deletions
|
|
@ -381,8 +381,10 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
|
||||||
|
|
||||||
/* Make a modifiable copy of the code string */
|
/* Make a modifiable copy of the code string */
|
||||||
codestr = (unsigned char *)PyMem_Malloc(codelen);
|
codestr = (unsigned char *)PyMem_Malloc(codelen);
|
||||||
if (codestr == NULL)
|
if (codestr == NULL) {
|
||||||
|
PyErr_NoMemory();
|
||||||
goto exitError;
|
goto exitError;
|
||||||
|
}
|
||||||
codestr = (unsigned char *)memcpy(codestr,
|
codestr = (unsigned char *)memcpy(codestr,
|
||||||
PyBytes_AS_STRING(code), codelen);
|
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 */
|
/* Mapping to new jump targets after NOPs are removed */
|
||||||
addrmap = (int *)PyMem_Malloc(codelen * sizeof(int));
|
addrmap = (int *)PyMem_Malloc(codelen * sizeof(int));
|
||||||
if (addrmap == NULL)
|
if (addrmap == NULL) {
|
||||||
|
PyErr_NoMemory();
|
||||||
goto exitError;
|
goto exitError;
|
||||||
|
}
|
||||||
|
|
||||||
blocks = markblocks(codestr, codelen);
|
blocks = markblocks(codestr, codelen);
|
||||||
if (blocks == NULL)
|
if (blocks == NULL)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue