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; } }