Skip to content

Commit d75ec9a

Browse files
committed
Make sure we store new stackrefs for frame executable/funcobj
These need to be tagged appropriately, not just increfed, so that they are decrefed when the frame is destroyed.
1 parent eee2195 commit d75ec9a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Include/internal/pycore_frame.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ static inline void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *
158158
}
159159
// XXX - More efficient version of this?
160160
if (_PyStackRef_IsBorrowed(dest->f_executable)) {
161-
Py_INCREF(PyStackRef_AsPyObjectBorrow(dest->f_executable));
161+
dest->f_executable = PyStackRef_FromPyObjectNew(PyStackRef_AsPyObjectBorrow(dest->f_executable));
162162
}
163163
if (_PyStackRef_IsBorrowed(dest->f_funcobj)) {
164-
Py_INCREF(PyStackRef_AsPyObjectBorrow(dest->f_funcobj));
164+
dest->f_funcobj = PyStackRef_FromPyObjectNew(PyStackRef_AsPyObjectBorrow(dest->f_funcobj));
165165
}
166166
// Don't leave a dangling pointer to the old frame when creating generators
167167
// and coroutines:

Python/frame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
5959
assert(stacktop >= _PyFrame_GetCode(frame)->co_nlocalsplus);
6060
// XXX - Maybe more optimal sequence to do here
6161
if (_PyStackRef_IsBorrowed(frame->f_executable)) {
62-
Py_INCREF(PyStackRef_AsPyObjectBorrow(frame->f_executable));
62+
frame->f_executable = PyStackRef_FromPyObjectNew(PyStackRef_AsPyObjectBorrow(frame->f_executable));
6363
}
6464
if (_PyStackRef_IsBorrowed(frame->f_funcobj)) {
65-
Py_INCREF(PyStackRef_AsPyObjectBorrow(frame->f_funcobj));
65+
frame->f_funcobj = PyStackRef_FromPyObjectNew(PyStackRef_AsPyObjectBorrow(frame->f_funcobj));
6666
}
6767
for (int i = 0; i < stacktop; i++) {
6868
frame->localsplus[i] = _PyStackRef_StealIfUnborrowed(frame->localsplus[i]);

0 commit comments

Comments
 (0)