https://github.com/python/cpython/commit/6763bfcc0fbab7895514c1f954d79a2555036323
commit: 6763bfcc0fbab7895514c1f954d79a2555036323
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2024-05-01T21:51:40+01:00
summary:

gh-118272: set stacktop to 0 before freeing contents, to avoid access to 
invalid objects during GC (#118478)

files:
M Python/frame.c

diff --git a/Python/frame.c b/Python/frame.c
index ec390e7426ad47..2bb12823572028 100644
--- a/Python/frame.c
+++ b/Python/frame.c
@@ -98,10 +98,11 @@ void
 _PyFrame_ClearLocals(_PyInterpreterFrame *frame)
 {
     assert(frame->stacktop >= 0);
-    for (int i = 0; i < frame->stacktop; i++) {
+    int stacktop = frame->stacktop;
+    frame->stacktop = 0;
+    for (int i = 0; i < stacktop; i++) {
         Py_XDECREF(frame->localsplus[i]);
     }
-    frame->stacktop = 0;
     Py_CLEAR(frame->f_locals);
 }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to