diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-08 00:14:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-08 00:14:47 (GMT) |
commit | bcb198385dee469d630a184182df9dc1463e2c47 (patch) | |
tree | 193bc5c3584732b506223a34f3215a03fd1be408 /Objects/frameobject.c | |
parent | c96a61e8163c2d25ed4ac77cf96201fd0bdb945c (diff) | |
download | cpython-bcb198385dee469d630a184182df9dc1463e2c47.zip cpython-bcb198385dee469d630a184182df9dc1463e2c47.tar.gz cpython-bcb198385dee469d630a184182df9dc1463e2c47.tar.bz2 |
bpo-40887: Don't use finalized free lists (GH-20700)
In debug mode, ensure that free lists are no longer used after being
finalized. Set numfree to -1 in finalization functions
(eg. _PyList_Fini()), and then check that numfree is not equal to -1
before using a free list (e.g list_dealloc()).
Diffstat (limited to 'Objects/frameobject.c')
-rw-r--r-- | Objects/frameobject.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 0fe9f2a..0dad42e 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -595,6 +595,10 @@ frame_dealloc(PyFrameObject *f) else { PyInterpreterState *interp = _PyInterpreterState_GET(); struct _Py_frame_state *state = &interp->frame; +#ifdef Py_DEBUG + // frame_dealloc() must not be called after _PyFrame_Fini() + assert(state->numfree != -1); +#endif if (state->numfree < PyFrame_MAXFREELIST) { ++state->numfree; f->f_back = state->free_list; @@ -790,6 +794,10 @@ frame_alloc(PyCodeObject *code) } } else { +#ifdef Py_DEBUG + // frame_alloc() must not be called after _PyFrame_Fini() + assert(state->numfree != -1); +#endif assert(state->numfree > 0); --state->numfree; f = state->free_list; @@ -1188,6 +1196,10 @@ void _PyFrame_Fini(PyThreadState *tstate) { _PyFrame_ClearFreeList(tstate); +#ifdef Py_DEBUG + struct _Py_frame_state *state = &tstate->interp->frame; + state->numfree = -1; +#endif } /* Print summary info about the state of the optimized allocator */ |