Skip to content

Commit fbe0f41

Browse files
committed
gh-130809: Fix PyFrame_LocalsToFast copying the wrong value
1 parent 519dec9 commit fbe0f41

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Objects/frameobject.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,14 +1399,14 @@ _PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear)
13991399

14001400
PyObject *exc = PyErr_GetRaisedException();
14011401
for (int i = 0; i < co->co_nlocalsplus; i++) {
1402-
_PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
1403-
1404-
/* Same test as in PyFrame_FastToLocals() above. */
1405-
if (kind & CO_FAST_FREE && !(co->co_flags & CO_OPTIMIZED)) {
1402+
/* Same test as in _PyFrame_GetLocals() above. */
1403+
PyObject *value; // borrowed reference
1404+
if (!frame_get_var(frame, co, i, &value)) {
14061405
continue;
14071406
}
1407+
14081408
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
1409-
PyObject *value = PyObject_GetItem(locals, name);
1409+
_PyLocals_Kind kind = _PyLocals_GetKind(co->co_localspluskinds, i);
14101410
/* We only care about NULLs if clear is true. */
14111411
if (value == NULL) {
14121412
PyErr_Clear();
@@ -1452,7 +1452,6 @@ _PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear)
14521452
}
14531453
Py_XSETREF(fast[i], Py_NewRef(value));
14541454
}
1455-
Py_XDECREF(value);
14561455
}
14571456
PyErr_SetRaisedException(exc);
14581457
}

0 commit comments

Comments
 (0)