Skip to content

Commit 1de88f6

Browse files
committed
Fix reference leaks (needs cleanup)
1 parent 65219b2 commit 1de88f6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Python/ceval.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -5648,7 +5648,12 @@ _PyEvalFramePushAndInit(PyThreadState *tstate, PyFrameConstructor *con,
56485648
PyObject **localsarray = _PyFrame_GetLocalsArray(frame);
56495649
if (initialize_locals(tstate, con, localsarray, args, argcount, kwnames, steal_args)) {
56505650
if (steal_args) {
5651-
for (int i = 0; i < frame->stacktop; i++) {
5651+
// If we failed to initialize locals, make sure the caller still own all the
5652+
// arguments. Notice that we only need to increase the reference count of the
5653+
// *valid* arguments (i.e. the ones that fit into the frame).
5654+
PyCodeObject *co = (PyCodeObject*)con->fc_code;
5655+
const Py_ssize_t total_args = co->co_argcount + co->co_kwonlyargcount;
5656+
for (Py_ssize_t i = 0; i < Py_MIN(argcount, total_args); i++) {
56525657
Py_XINCREF(frame->localsplus[i]);
56535658
}
56545659
}

0 commit comments

Comments
 (0)