From 7ec2e279fea3b340f642cff888bfa45368f5ded0 Mon Sep 17 00:00:00 2001 From: Ken Jin Date: Tue, 11 Oct 2022 23:11:46 +0800 Subject: [PATCH] gh-95756: Free and NULL-out code caches when needed (GH-98181) --- Objects/codeobject.c | 1 + Objects/frameobject.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 7a0080c08c7..8920b1db2ca 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -2238,6 +2238,7 @@ _PyStaticCode_Dealloc(PyCodeObject *co) Py_CLEAR(co->_co_cached->_co_freevars); Py_CLEAR(co->_co_cached->_co_varnames); PyMem_Free(co->_co_cached); + co->_co_cached = NULL; } co->co_extra = NULL; if (co->co_weakreflist != NULL) { diff --git a/Objects/frameobject.c b/Objects/frameobject.c index bd1608e0d75..8b4494a5fe8 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -651,6 +651,8 @@ add_load_fast_null_checks(PyCodeObject *co) Py_CLEAR(co->_co_cached->_co_cellvars); Py_CLEAR(co->_co_cached->_co_freevars); Py_CLEAR(co->_co_cached->_co_varnames); + PyMem_Free(co->_co_cached); + co->_co_cached = NULL; } }