[前][次][番号順一覧][スレッド一覧]

ruby-changes:74200

From: Jemma <ko1@a...>
Date: Sat, 22 Oct 2022 02:57:26 +0900 (JST)
Subject: [ruby-changes:74200] f2ae58119d (master): In init_copy, set shape after copying ivars

https://git.ruby-lang.org/ruby.git/commit/?id=f2ae58119d

From f2ae58119d9581dee467b0a7f05173eca3b2dfea Mon Sep 17 00:00:00 2001
From: Jemma Issroff <jemmaissroff@g...>
Date: Thu, 20 Oct 2022 14:50:41 -0400
Subject: 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.
---
 object.c | 6 +++---
 1 file 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) https://github.com/ruby/ruby/blob/trunk/object.c#L306
         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);
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]