diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -864,8 +864,11 @@ if (obj == Py_None) obj = NULL; if (obj) - PyArena_AddPyObject(arena, obj); - Py_XINCREF(obj); + if (PyArena_AddPyObject(arena, obj) < 0) { + *out = NULL; + return -1; + } + Py_INCREF(obj); *out = obj; return 0; } diff --git a/Python/Python-ast.c b/Python/Python-ast.c --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -705,8 +705,11 @@ if (obj == Py_None) obj = NULL; if (obj) - PyArena_AddPyObject(arena, obj); - Py_XINCREF(obj); + if (PyArena_AddPyObject(arena, obj) < 0) { + *out = NULL; + return -1; + } + Py_INCREF(obj); *out = obj; return 0; }