From: Donghee Na Date: Wed, 6 Mar 2024 23:29:39 +0000 (+0900) Subject: gh-116397: Move the _PyGC_ClearAllFreeLists to the safe point (gh-116414) X-Git-Tag: v3.13.0a5~74 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2d4955fcf2a54d7ffc06a48774863ff65ba250d2;p=thirdparty%2FPython%2Fcpython.git gh-116397: Move the _PyGC_ClearAllFreeLists to the safe point (gh-116414) --- diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c index 18893c6c391f..c7883cd38644 100644 --- a/Python/gc_free_threading.c +++ b/Python/gc_free_threading.c @@ -1058,6 +1058,8 @@ gc_collect_internal(PyInterpreterState *interp, struct collection_state *state) // Handle any objects that may have resurrected after the finalization. _PyEval_StopTheWorld(interp); err = handle_resurrected_objects(state); + // Clear free lists in all threads + _PyGC_ClearAllFreeLists(interp); _PyEval_StartTheWorld(interp); if (err < 0) { @@ -1160,8 +1162,9 @@ gc_collect_main(PyThreadState *tstate, int generation, _PyGC_Reason reason) n+m, n, d); } - // Clear free lists in all threads - _PyGC_ClearAllFreeLists(interp); + // Clear the current thread's free-list again. + _PyThreadStateImpl *tstate_impl = (_PyThreadStateImpl *)tstate; + _PyObject_ClearFreeLists(&tstate_impl->freelists, 0); if (_PyErr_Occurred(tstate)) { if (reason == _Py_GC_REASON_SHUTDOWN) {