[Python-checkins] gh-95756: Free and NULL-out code caches when needed (GH-98181)

Fidget-Spinner webhook-mailer at python.org
Tue Oct 11 11:11:57 EDT 2022


https://github.com/python/cpython/commit/7ec2e279fea3b340f642cff888bfa45368f5ded0
commit: 7ec2e279fea3b340f642cff888bfa45368f5ded0
branch: main
author: Ken Jin <kenjin at python.org>
committer: Fidget-Spinner <kenjin at python.org>
date: 2022-10-11T23:11:46+08:00
summary:

gh-95756: Free and NULL-out code caches when needed (GH-98181)

files:
M Objects/codeobject.c
M Objects/frameobject.c

diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 7a0080c08c7b..8920b1db2cad 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 bd1608e0d75a..8b4494a5fe82 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;
     }
 }
 



More information about the Python-checkins mailing list