[Python-checkins] cpython: Issue #18408: Handle PyArena_AddPyObject() failure in ast.c

victor.stinner python-checkins at python.org
Wed Jul 17 01:01:28 CEST 2013


http://hg.python.org/cpython/rev/8c1ca6720246
changeset:   84682:8c1ca6720246
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Jul 17 00:57:58 2013 +0200
summary:
  Issue #18408: Handle PyArena_AddPyObject() failure in ast.c

PyList_Append() (called by PyArena_AddPyObject()) can fail because of a
MemoryError for example.

files:
  Python/ast.c |  25 ++++++++++++++++++++-----
  1 files changed, 20 insertions(+), 5 deletions(-)


diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -560,7 +560,10 @@
         id = id2;
     }
     PyUnicode_InternInPlace(&id);
-    PyArena_AddPyObject(c->c_arena, id);
+    if (PyArena_AddPyObject(c->c_arena, id) < 0) {
+        Py_DECREF(id);
+        return NULL;
+    }
     return id;
 }
 
@@ -1847,7 +1850,10 @@
             }
             return NULL;
         }
-        PyArena_AddPyObject(c->c_arena, str);
+        if (PyArena_AddPyObject(c->c_arena, str) < 0) {
+            Py_DECREF(str);
+            return NULL;
+        }
         if (bytesmode)
             return Bytes(str, LINENO(n), n->n_col_offset, c->c_arena);
         else
@@ -1858,7 +1864,10 @@
         if (!pynum)
             return NULL;
 
-        PyArena_AddPyObject(c->c_arena, pynum);
+        if (PyArena_AddPyObject(c->c_arena, pynum) < 0) {
+            Py_DECREF(pynum);
+            return NULL;
+        }
         return Num(pynum, LINENO(n), n->n_col_offset, c->c_arena);
     }
     case ELLIPSIS: /* Ellipsis */
@@ -2845,13 +2854,19 @@
                     return NULL;
                 str = uni;
                 PyUnicode_InternInPlace(&str);
-                PyArena_AddPyObject(c->c_arena, str);
+                if (PyArena_AddPyObject(c->c_arena, str) < 0) {
+                    Py_DECREF(str);
+                    return NULL;
+                }
                 return alias(str, NULL, c->c_arena);
             }
             break;
         case STAR:
             str = PyUnicode_InternFromString("*");
-            PyArena_AddPyObject(c->c_arena, str);
+            if (PyArena_AddPyObject(c->c_arena, str) < 0) {
+                Py_DECREF(str);
+                return NULL;
+            }
             return alias(str, NULL, c->c_arena);
         default:
             PyErr_Format(PyExc_SystemError,

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list