Skip to content

Commit

Permalink
fix memory leakage
Browse files Browse the repository at this point in the history
  • Loading branch information
sunmy2019 committed Mar 31, 2023
1 parent a9e4785 commit d8b12e2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Parser/action_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1373,9 +1373,16 @@ expr_ty _PyPegen_constant_from_string(Parser* p, Token* tok) {
_Pypegen_raise_decode_error(p);
return NULL;
}
if (_PyArena_AddPyObject(p->arena, s) < 0) {
Py_DECREF(s);
return NULL;
}
PyObject *kind = NULL;
if (the_str && the_str[0] == 'u') {
kind = _PyPegen_new_identifier(p, "u");
if (kind == NULL) {
return NULL;
}
}
return _PyAST_Constant(s, kind, tok->lineno, tok->col_offset, tok->end_lineno, tok->end_col_offset, p->arena);
}
Expand Down Expand Up @@ -1488,7 +1495,8 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
expr_ty elem = asdl_seq_GET(strings, i);
PyBytes_Concat(&res, elem->v.Constant.value);
}
if (_PyArena_AddPyObject(arena, res) < 0) {
if (!res || _PyArena_AddPyObject(arena, res) < 0) {
Py_XDECREF(res);
return NULL;
}
return _PyAST_Constant(res, kind, lineno, col_offset, end_lineno, end_col_offset, p->arena);
Expand Down Expand Up @@ -1589,13 +1597,15 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
_PyUnicodeWriter_Dealloc(&writer);
return NULL;
}

if (_PyArena_AddPyObject(p->arena, concat_str) < 0) {
Py_DECREF(concat_str);
return NULL;
}
elem = _PyAST_Constant(concat_str, kind, first_elem->lineno,
first_elem->col_offset,
last_elem->end_lineno,
last_elem->end_col_offset, p->arena);
if (elem == NULL) {
Py_DECREF(concat_str);
return NULL;
}
}
Expand Down

0 comments on commit d8b12e2

Please sign in to comment.