Skip to content

Commit 5833e94

Browse files
authored
bpo-36817: Fix reference leak for expr_text in f-string = parsing (GH-13249)
1 parent 90fb04c commit 5833e94

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Python/ast.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5228,10 +5228,15 @@ fstring_find_expr(const char **str, const char *end, int raw, int recurse_lvl,
52285228

52295229
}
52305230
if (equal_flag) {
5231-
Py_ssize_t len = expr_text_end-expr_start;
5231+
Py_ssize_t len = expr_text_end - expr_start;
52325232
expr_text = PyUnicode_FromStringAndSize(expr_start, len);
5233-
if (!expr_text)
5233+
if (!expr_text) {
52345234
goto error;
5235+
}
5236+
if (PyArena_AddPyObject(c->c_arena, expr_text) < 0) {
5237+
Py_DECREF(expr_text);
5238+
goto error;
5239+
}
52355240
}
52365241

52375242
/* Check for the format spec, if present. */

0 commit comments

Comments
 (0)