From 2c6dd5cf0c6198c2b607a7079b95079256c203e5 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Sun, 4 Feb 2024 01:58:17 +0000 Subject: [PATCH] Set old space for objects in finalizer list before adding to old space --- Python/gc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Python/gc.c b/Python/gc.c index cda12ff7fbc982..6b59545282a942 100644 --- a/Python/gc.c +++ b/Python/gc.c @@ -1003,10 +1003,11 @@ handle_legacy_finalizers(PyThreadState *tstate, assert(!_PyErr_Occurred(tstate)); assert(gcstate->garbage != NULL); + int old_space = gc_old_space(old); PyGC_Head *gc = GC_NEXT(finalizers); for (; gc != finalizers; gc = GC_NEXT(gc)) { + gc_set_old_space(gc, old_space); PyObject *op = FROM_GC(gc); - if ((gcstate->debug & _PyGC_DEBUG_SAVEALL) || has_legacy_finalizer(op)) { if (PyList_Append(gcstate->garbage, op) < 0) { _PyErr_Clear(tstate);