Skip to content

Commit 2191c56

Browse files
committed
gh-144986: Fix memory leak in atexit.register()
1 parent 1ddb412 commit 2191c56

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Modules/atexitmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,17 @@ atexit_register(PyObject *module, PyObject *args, PyObject *kwargs)
185185
return NULL;
186186
}
187187
PyObject *func_args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args));
188+
if (func_args == NULL) {
189+
return NULL;
190+
}
188191
PyObject *func_kwargs = kwargs;
189192

190193
if (func_kwargs == NULL)
191194
{
192195
func_kwargs = Py_None;
193196
}
194197
PyObject *callback = PyTuple_Pack(3, func, func_args, func_kwargs);
198+
Py_DECREF(func_args);
195199
if (callback == NULL)
196200
{
197201
return NULL;

Parser/action_helpers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ _build_concatenated_bytes(Parser *p, asdl_expr_seq *strings, int lineno,
16831683
Py_DECREF(res);
16841684
return NULL;
16851685
}
1686-
return _PyAST_Constant(res, kind, lineno, col_offset, end_lineno, end_col_offset, p->arena);
1686+
return _PyAST_Constant(res, kind, lineno, col_offset, end_lineno, end_col_offset, arena);
16871687
}
16881688

16891689
static expr_ty
@@ -1724,7 +1724,7 @@ _build_concatenated_unicode(Parser *p, asdl_expr_seq *strings, int lineno,
17241724
if (final == NULL) {
17251725
return NULL;
17261726
}
1727-
if (_PyArena_AddPyObject(p->arena, final) < 0) {
1727+
if (_PyArena_AddPyObject(arena, final) < 0) {
17281728
Py_DECREF(final);
17291729
return NULL;
17301730
}
@@ -1895,7 +1895,7 @@ _build_concatenated_joined_str(Parser *p, asdl_expr_seq *strings,
18951895
{
18961896
asdl_expr_seq *values = _build_concatenated_str(p, strings, lineno,
18971897
col_offset, end_lineno, end_col_offset, arena);
1898-
return _PyAST_JoinedStr(values, lineno, col_offset, end_lineno, end_col_offset, p->arena);
1898+
return _PyAST_JoinedStr(values, lineno, col_offset, end_lineno, end_col_offset, arena);
18991899
}
19001900

19011901
expr_ty

0 commit comments

Comments
 (0)