summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2024-05-01 20:51:40 (GMT)
committerGitHub <noreply@github.com>2024-05-01 20:51:40 (GMT)
commit6763bfcc0fbab7895514c1f954d79a2555036323 (patch)
treebe12782a3c045e5785dd0cbe9dc19d03fb4ba6e2 /Python
parent1161ab9085ee6e2d6efdf497c81129ba0837031b (diff)
downloadcpython-6763bfcc0fbab7895514c1f954d79a2555036323.zip
cpython-6763bfcc0fbab7895514c1f954d79a2555036323.tar.gz
cpython-6763bfcc0fbab7895514c1f954d79a2555036323.tar.bz2
gh-118272: set stacktop to 0 before freeing contents, to avoid access to invalid objects during GC (#118478)
Diffstat (limited to 'Python')
-rw-r--r--Python/frame.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Python/frame.c b/Python/frame.c
index ec390e7..2bb1282 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);
}