Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit585c95d

Browse files
miss-islingtonpablogsal
authored andcommitted
[3.11]GH-97752: Clear the previous member of newly-created generator/coroutine frames (GH-97812)
(cherry picked from commit93fcc1f)
1 parent4e0fda5 commit585c95d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

‎Lib/test/test_generators.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,25 @@ def __del__(self):
206206
finally:
207207
gc.set_threshold(*thresholds)
208208

209+
deftest_ag_frame_f_back(self):
210+
asyncdeff():
211+
yield
212+
ag=f()
213+
self.assertIsNone(ag.ag_frame.f_back)
214+
215+
deftest_cr_frame_f_back(self):
216+
asyncdeff():
217+
pass
218+
cr=f()
219+
self.assertIsNone(cr.cr_frame.f_back)
220+
cr.close()# Suppress RuntimeWarning.
221+
222+
deftest_gi_frame_f_back(self):
223+
deff():
224+
yield
225+
gi=f()
226+
self.assertIsNone(gi.gi_frame.f_back)
227+
209228

210229

211230
classExceptionTest(unittest.TestCase):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix possible data corruption or crashes when accessing the ``f_back`` member
2+
of newly-created generator or coroutine frames.

‎Python/frame.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest)
6969
assert(src->stacktop >=src->f_code->co_nlocalsplus);
7070
Py_ssize_tsize= ((char*)&src->localsplus[src->stacktop])- (char*)src;
7171
memcpy(dest,src,size);
72+
// Don't leave a dangling pointer to the old frame when creating generators
73+
// and coroutines:
74+
dest->previous=NULL;
7275
}
7376

7477

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp