Skip to content

Commit 5e90d9e

Browse files
committed
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.
1 parent b897a47 commit 5e90d9e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

gc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,18 @@ newobj_of(rb_ractor_t *cr, VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v
10101010
RB_VM_LOCK_LEAVE_CR_LEV(cr, &lev);
10111011
}
10121012

1013+
#if RGENGC_CHECK_MODE
1014+
# ifndef GC_DEBUG_SLOT_FILL_SPECIAL_VALUE
1015+
# define GC_DEBUG_SLOT_FILL_SPECIAL_VALUE 255
1016+
# endif
1017+
1018+
memset(
1019+
(void *)(obj + RVALUE_SIZE),
1020+
GC_DEBUG_SLOT_FILL_SPECIAL_VALUE,
1021+
rb_gc_obj_slot_size(obj) - RVALUE_SIZE
1022+
);
1023+
#endif
1024+
10131025
return obj;
10141026
}
10151027

0 commit comments

Comments
 (0)