1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

In init_copy, set shape after copying ivars

GC uses shapes to determine IV buffer width. Since allocation can
trigger GC, we need to ensure we only set the shape once we've fully
allocated new memory for the IV buffer, otherwise the GC can end up
trying to mark invalid memory.
This commit is contained in:
Jemma Issroff 2022-10-20 14:50:41 -04:00 committed by Aaron Patterson
parent 35e03a44b8
commit f2ae58119d
Notes: git 2022-10-21 17:57:27 +00:00

View file

@ -306,12 +306,12 @@ init_copy(VALUE dest, VALUE obj)
shape_to_set = rb_shape_get_shape_by_id(shape_to_set->parent_id);
}
// shape ids are different
rb_shape_set_shape(dest, shape_to_set);
if (RB_TYPE_P(obj, T_OBJECT)) {
rb_obj_copy_ivar(dest, obj);
}
// shape ids are different
rb_shape_set_shape(dest, shape_to_set);
}
static VALUE immutable_obj_clone(VALUE obj, VALUE kwfreeze);