Skip to content

Commit d8b12e2

Browse files
committed
fix memory leakage
1 parent a9e4785 commit d8b12e2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Parser/action_helpers.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,9 +1373,16 @@ expr_ty _PyPegen_constant_from_string(Parser* p, Token* tok) {
13731373
_Pypegen_raise_decode_error(p);
13741374
return NULL;
13751375
}
1376+
if (_PyArena_AddPyObject(p->arena, s) < 0) {
1377+
Py_DECREF(s);
1378+
return NULL;
1379+
}
13761380
PyObject *kind = NULL;
13771381
if (the_str && the_str[0] == 'u') {
13781382
kind = _PyPegen_new_identifier(p, "u");
1383+
if (kind == NULL) {
1384+
return NULL;
1385+
}
13791386
}
13801387
return _PyAST_Constant(s, kind, tok->lineno, tok->col_offset, tok->end_lineno, tok->end_col_offset, p->arena);
13811388
}
@@ -1488,7 +1495,8 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
14881495
expr_ty elem = asdl_seq_GET(strings, i);
14891496
PyBytes_Concat(&res, elem->v.Constant.value);
14901497
}
1491-
if (_PyArena_AddPyObject(arena, res) < 0) {
1498+
if (!res || _PyArena_AddPyObject(arena, res) < 0) {
1499+
Py_XDECREF(res);
14921500
return NULL;
14931501
}
14941502
return _PyAST_Constant(res, kind, lineno, col_offset, end_lineno, end_col_offset, p->arena);
@@ -1589,13 +1597,15 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
15891597
_PyUnicodeWriter_Dealloc(&writer);
15901598
return NULL;
15911599
}
1592-
1600+
if (_PyArena_AddPyObject(p->arena, concat_str) < 0) {
1601+
Py_DECREF(concat_str);
1602+
return NULL;
1603+
}
15931604
elem = _PyAST_Constant(concat_str, kind, first_elem->lineno,
15941605
first_elem->col_offset,
15951606
last_elem->end_lineno,
15961607
last_elem->end_col_offset, p->arena);
15971608
if (elem == NULL) {
1598-
Py_DECREF(concat_str);
15991609
return NULL;
16001610
}
16011611
}

0 commit comments

Comments
 (0)