diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index b71565c53f..4902486222 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -946,6 +946,7 @@ def visitModule(self, mod): obj = NULL; if (obj) { if (_PyArena_AddPyObject(arena, obj) < 0) { + Py_DECREF(obj); *out = NULL; return -1; } @@ -958,6 +959,7 @@ def visitModule(self, mod): static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) { if (_PyArena_AddPyObject(arena, obj) < 0) { + Py_DECREF(obj); *out = NULL; return -1; } diff --git a/Parser/pegen.c b/Parser/pegen.c index 82dcd3bb5a..7b5a5e9146 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -690,7 +690,10 @@ _PyPegen_fill_token(Parser *p) if (t->bytes == NULL) { return -1; } - _PyArena_AddPyObject(p->arena, t->bytes); + if (_PyArena_AddPyObject(p->arena, t->bytes) < 0) { + Py_DECREF(t->bytes); + return -1; + } int lineno = type == STRING ? p->tok->first_lineno : p->tok->lineno; const char *line_start = type == STRING ? p->tok->multi_line_start : p->tok->line_start; diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 2105729ea3..a75927301a 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -955,6 +955,7 @@ static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyO obj = NULL; if (obj) { if (_PyArena_AddPyObject(arena, obj) < 0) { + Py_DECREF(obj); *out = NULL; return -1; } @@ -967,6 +968,7 @@ static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyO static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena) { if (_PyArena_AddPyObject(arena, obj) < 0) { + Py_DECREF(obj); *out = NULL; return -1; }