Skip to content

Commit

Permalink
Fix refleak in _BINARY_OP_INPLACE_ADD_UNICODE
Browse files Browse the repository at this point in the history
PyStackRef_AsPyObjectSteal creates a new reference if the stackref
is deferred. This reference is leaked if we deopt before the corresponding
decref.
  • Loading branch information
mpage committed Feb 21, 2025
1 parent a4b9973 commit 12921fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,8 @@ dummy_func(
// At the end we just skip over the STORE_FAST.
op(_BINARY_OP_INPLACE_ADD_UNICODE, (left, right --)) {
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
PyObject *right_o = PyStackRef_AsPyObjectSteal(right);
assert(PyUnicode_CheckExact(left_o));
assert(PyUnicode_CheckExact(right_o));
assert(PyUnicode_CheckExact(PyStackRef_AsPyObjectBorrow(right)));

int next_oparg;
#if TIER_ONE
Expand All @@ -761,6 +760,7 @@ dummy_func(
PyStackRef_CLOSE_SPECIALIZED(left, _PyUnicode_ExactDealloc);
DEAD(left);
PyObject *temp = PyStackRef_AsPyObjectSteal(*target_local);
PyObject *right_o = PyStackRef_AsPyObjectSteal(right);
PyUnicode_Append(&temp, right_o);
*target_local = PyStackRef_FromPyObjectSteal(temp);
Py_DECREF(right_o);
Expand Down
4 changes: 2 additions & 2 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 12921fd

Please sign in to comment.