]> granicus.if.org Git - python/commitdiff
Issue #18408: Fix PyCode_Optimize(): raise a MemoryError on memory allocation
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 8 Jul 2013 22:32:04 +0000 (00:32 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 8 Jul 2013 22:32:04 +0000 (00:32 +0200)
failure.

Python/peephole.c

index e6877bb3e6a5ba7527476c36403361e02f501873..a49790a60f896ab747b8ca054b2704f2778d7c53 100644 (file)
@@ -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)