mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
GH-97752: Clear the previous
member of newly-created generator/coroutine frames (GH-97795)
This commit is contained in:
parent
d053c47bfd
commit
93fcc1f413
3 changed files with 24 additions and 0 deletions
|
@ -206,6 +206,25 @@ class GeneratorTest(unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
gc.set_threshold(*thresholds)
|
gc.set_threshold(*thresholds)
|
||||||
|
|
||||||
|
def test_ag_frame_f_back(self):
|
||||||
|
async def f():
|
||||||
|
yield
|
||||||
|
ag = f()
|
||||||
|
self.assertIsNone(ag.ag_frame.f_back)
|
||||||
|
|
||||||
|
def test_cr_frame_f_back(self):
|
||||||
|
async def f():
|
||||||
|
pass
|
||||||
|
cr = f()
|
||||||
|
self.assertIsNone(cr.cr_frame.f_back)
|
||||||
|
cr.close() # Suppress RuntimeWarning.
|
||||||
|
|
||||||
|
def test_gi_frame_f_back(self):
|
||||||
|
def f():
|
||||||
|
yield
|
||||||
|
gi = f()
|
||||||
|
self.assertIsNone(gi.gi_frame.f_back)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExceptionTest(unittest.TestCase):
|
class ExceptionTest(unittest.TestCase):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix possible data corruption or crashes when accessing the ``f_back`` member
|
||||||
|
of newly-created generator or coroutine frames.
|
|
@ -54,6 +54,9 @@ _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
|
||||||
assert(src->stacktop >= src->f_code->co_nlocalsplus);
|
assert(src->stacktop >= src->f_code->co_nlocalsplus);
|
||||||
Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src;
|
Py_ssize_t size = ((char*)&src->localsplus[src->stacktop]) - (char *)src;
|
||||||
memcpy(dest, src, size);
|
memcpy(dest, src, size);
|
||||||
|
// Don't leave a dangling pointer to the old frame when creating generators
|
||||||
|
// and coroutines:
|
||||||
|
dest->previous = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue