From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Wed, 1 May 2024 20:51:40 +0000 (+0100) Subject: gh-118272: set stacktop to 0 before freeing contents, to avoid access to invalid... X-Git-Tag: v3.13.0b1~173 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6763bfcc0fbab7895514c1f954d79a2555036323;p=thirdparty%2FPython%2Fcpython.git gh-118272: set stacktop to 0 before freeing contents, to avoid access to invalid objects during GC (#118478) --- diff --git a/Python/frame.c b/Python/frame.c index ec390e7426ad..2bb128235720 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); }