]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118272: set stacktop to 0 before freeing contents, to avoid access to invalid...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Wed, 1 May 2024 20:51:40 +0000 (21:51 +0100)
committerGitHub <noreply@github.com>
Wed, 1 May 2024 20:51:40 +0000 (21:51 +0100)
Python/frame.c

index ec390e7426ad4701dbe2e8e98dd285c8b0f4304f..2bb1282357202849fa537863c1739b458e163d57 100644 (file)
@@ -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);
 }