summaryrefslogtreecommitdiff
path: root/object.c
diff options
context:
space:
mode:
authorJemma Issroff <jemmaissroff@gmail.com>2022-10-20 14:50:41 -0400
committerAaron Patterson <aaron.patterson@gmail.com>2022-10-21 10:57:05 -0700
commitf2ae58119d9581dee467b0a7f05173eca3b2dfea (patch)
treebd88011a256a9101a26af4835a214ad1a7b22141 /object.c
parent35e03a44b815c1111e3947ba526a5de0bdf82c82 (diff)
downloadruby-f2ae58119d9581dee467b0a7f05173eca3b2dfea.tar.gz
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.
Diffstat (limited to 'object.c')
-rw-r--r--object.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/object.c b/object.c
index fd07944d14..aae6cc45a4 100644
--- a/object.c
+++ b/object.c
@@ -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);