From 5131fb5dbe6565bd16883aad94b9daec8ec56c51 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 21 Oct 2024 10:25:34 -0400 Subject: [PATCH] Don't clear out flags in rb_gc_obj_free If there's a crash after rb_gc_obj_free, it's hard to debug because the flags have been cleared out already. --- gc.c | 1 - gc/default.c | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gc.c b/gc.c index dc17f3bf318f79..e67d1c0b8e1147 100644 --- a/gc.c +++ b/gc.c @@ -1314,7 +1314,6 @@ rb_gc_obj_free(void *objspace, VALUE obj) return FALSE; } else { - RBASIC(obj)->flags = 0; return TRUE; } } diff --git a/gc/default.c b/gc/default.c index dac7aaeed63ff5..50ad291081e447 100644 --- a/gc/default.c +++ b/gc/default.c @@ -3030,7 +3030,9 @@ rb_gc_impl_shutdown_free_objects(void *objspace_ptr) VALUE vp = (VALUE)p; asan_unpoisoning_object(vp) { if (RB_BUILTIN_TYPE(vp) != T_NONE) { - rb_gc_obj_free(objspace, vp); + if (rb_gc_obj_free(objspace, vp)) { + RBASIC(vp)->flags = 0; + } } } } @@ -3102,7 +3104,9 @@ rb_gc_impl_shutdown_call_finalizer(void *objspace_ptr) VALUE vp = (VALUE)p; asan_unpoisoning_object(vp) { if (rb_gc_shutdown_call_finalizer_p(vp)) { - rb_gc_obj_free(objspace, vp); + if (rb_gc_obj_free(objspace, vp)) { + RBASIC(vp)->flags = 0; + } } } }