From a50e35888b9bc5428a30b95c0ded12ddb986354f Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 5 Feb 2024 14:41:29 -0500 Subject: [PATCH] Free all remaining objects in rb_objspace_free_objects rb_objspace_call_finalizer didn't free fibers and neither did rb_objspace_free_objects, which caused fibers to be reported as leaked when using RUBY_FREE_AT_EXIT. This commit changes rb_objspace_free_objects to free all remaining Ruby objects. --- gc.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/gc.c b/gc.c index 7414e929a6..124f2158ff 100644 --- a/gc.c +++ b/gc.c @@ -3810,7 +3810,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj) RB_DEBUG_COUNTER_INC(obj_imemo_constcache); break; } - return TRUE; + break; default: rb_bug("gc_sweep(): unknown data type 0x%x(%p) 0x%"PRIxVALUE, @@ -3822,6 +3822,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj) return FALSE; } else { + RBASIC(obj)->flags = 0; return TRUE; } } @@ -4616,16 +4617,11 @@ rb_objspace_free_objects(rb_objspace_t *objspace) for (; p < pend; p += stride) { VALUE vp = (VALUE)p; switch (BUILTIN_TYPE(vp)) { - case T_DATA: { - if (rb_obj_is_mutex(vp) || rb_obj_is_thread(vp) || rb_obj_is_main_ractor(vp)) { - obj_free(objspace, vp); - } - break; - } - case T_ARRAY: - obj_free(objspace, vp); + case T_NONE: + case T_SYMBOL: break; default: + obj_free(objspace, vp); break; } }