From 5e90d9e2aabebd20c9566744687e63af65a633c0 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Fri, 12 Sep 2025 10:37:34 -0400 Subject: [PATCH] Fill extra space in newly allocated object with garbage This commit fills the space that is not initialized with garbage for newly allocated objects on debug mode. --- gc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gc.c b/gc.c index e8709dcf281a64..c412da188130e5 100644 --- a/gc.c +++ b/gc.c @@ -1010,6 +1010,18 @@ newobj_of(rb_ractor_t *cr, VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v RB_VM_LOCK_LEAVE_CR_LEV(cr, &lev); } +#if RGENGC_CHECK_MODE +# ifndef GC_DEBUG_SLOT_FILL_SPECIAL_VALUE +# define GC_DEBUG_SLOT_FILL_SPECIAL_VALUE 255 +# endif + + memset( + (void *)(obj + RVALUE_SIZE), + GC_DEBUG_SLOT_FILL_SPECIAL_VALUE, + rb_gc_obj_slot_size(obj) - RVALUE_SIZE + ); +#endif + return obj; }