Skip to content

Commit 1fb813c

Browse files
Fix refleaks.
1 parent 5e98b69 commit 1fb813c

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Objects/codeobject.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ PyObject *
10431043
_PyCode_GetVarnames(PyCodeObject *co)
10441044
{
10451045
if (co->co_varnames == NULL) {
1046+
// PyCodeObject owns this reference.
10461047
co->co_varnames = get_localsplus_names(co, CO_FAST_LOCAL,
10471048
co->co_nlocals);
10481049
if (co->co_varnames == NULL) {
@@ -1057,6 +1058,7 @@ PyObject *
10571058
_PyCode_GetCellvars(PyCodeObject *co)
10581059
{
10591060
if (co->co_cellvars == NULL) {
1061+
// PyCodeObject owns this reference.
10601062
co->co_cellvars = get_localsplus_names(co, CO_FAST_CELL,
10611063
co->co_ncellvars);
10621064
if (co->co_cellvars == NULL) {
@@ -1071,6 +1073,7 @@ PyObject *
10711073
_PyCode_GetFreevars(PyCodeObject *co)
10721074
{
10731075
if (co->co_freevars == NULL) {
1076+
// PyCodeObject owns this reference.
10741077
co->co_freevars = get_localsplus_names(co, CO_FAST_FREE,
10751078
co->co_nfreevars);
10761079
if (co->co_freevars == NULL) {
@@ -1517,6 +1520,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
15171520
return NULL;
15181521
}
15191522

1523+
PyCodeObject *co = NULL;
15201524
PyObject *varnames = NULL;
15211525
PyObject *cellvars = NULL;
15221526
PyObject *freevars = NULL;
@@ -1542,21 +1546,17 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
15421546
co_freevars = freevars;
15431547
}
15441548

1545-
PyCodeObject *co = PyCode_NewWithPosOnlyArgs(
1549+
co = PyCode_NewWithPosOnlyArgs(
15461550
co_argcount, co_posonlyargcount, co_kwonlyargcount, co_nlocals,
15471551
co_stacksize, co_flags, (PyObject*)co_code, co_consts, co_names,
15481552
co_varnames, co_freevars, co_cellvars, co_filename, co_name,
15491553
co_firstlineno, (PyObject*)co_linetable, (PyObject*)co_exceptiontable);
1550-
if (co == NULL) {
1551-
goto error;
1552-
}
1553-
return (PyObject *)co;
15541554

15551555
error:
15561556
Py_XDECREF(varnames);
15571557
Py_XDECREF(cellvars);
15581558
Py_XDECREF(freevars);
1559-
return NULL;
1559+
return (PyObject *)co;
15601560
}
15611561

15621562
/*[clinic input]

Python/compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,7 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, Py_ssize_t flags,
20882088
c->u->u_name,
20892089
co->co_name,
20902090
freevars);
2091+
Py_DECREF(freevars);
20912092
return 0;
20922093
}
20932094
ADDOP_I(c, LOAD_CLOSURE, arg);

Python/suggestions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ offer_suggestions_for_name_error(PyNameErrorObject *exc)
217217
return NULL;
218218
}
219219
PyObject *dir = PySequence_List(varnames);
220+
Py_DECREF(varnames);
220221
Py_DECREF(code);
221222
if (dir == NULL) {
222223
return NULL;

0 commit comments

Comments
 (0)