summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-11 09:15:20 (GMT)
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-11 09:15:20 (GMT)
commit5922c954614e5947a548780bb3b894626affe6dd (patch)
treec7de7025f8d3dbeb816aa99cd197e5adba33815e /class.c
parent5a62fdee4d166fe0eff14bc616e1befa8ad54cd2 (diff)
* gc.c: fix memory leak by prepend method.
It is easy to reproduce with such script: module M; def bar; end; end loop{ Class.new do def foo; end prepend M end } * gc.c (obj_free): free T_ICLASS::m_tbl if it is created by prepend. To recognize it, check RICLASS_IS_ORIGIN flag. * gc.c (gc_mark_children): T_ICLASS objects only need to mark T_ICLASS::m_tbl if RICLASS_IS_ORIGIN is set. * gc.c (obj_memsize_of): count T_ICLASS if RICLASS_IS_ORIGIN is set. * internal.h (RCLASS_SET_ORIGIN): add to set RCLASS_SET_ORIGIN. TODO: The word `origin' seems not good name. We need to invent another good name. * class.c: use RCLASS_SET_ORIGIN(). * class.c (class_alloc): zero clear rb_classext_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'class.c')
-rw-r--r--class.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/class.c b/class.c
index f11eb52..1121068 100644
--- a/class.c
+++ b/class.c
@@ -163,21 +163,22 @@ static VALUE
class_alloc(VALUE flags, VALUE klass)
{
NEWOBJ_OF(obj, struct RClass, klass, (flags & T_MASK) | FL_PROMOTED1 /* start from age == 2 */ | (RGENGC_WB_PROTECTED_CLASS ? FL_WB_PROTECTED : 0));
- obj->ptr = ALLOC(rb_classext_t);
- RCLASS_IV_TBL(obj) = 0;
- RCLASS_CONST_TBL(obj) = 0;
- RCLASS_M_TBL(obj) = 0;
- RCLASS_SET_SUPER((VALUE)obj, 0);
- RCLASS_ORIGIN(obj) = (VALUE)obj;
- RCLASS_IV_INDEX_TBL(obj) = 0;
-
- RCLASS_EXT(obj)->subclasses = NULL;
- RCLASS_EXT(obj)->parent_subclasses = NULL;
- RCLASS_EXT(obj)->module_subclasses = NULL;
+ obj->ptr = ZALLOC(rb_classext_t);
+ /* ZALLOC
+ RCLASS_IV_TBL(obj) = 0;
+ RCLASS_CONST_TBL(obj) = 0;
+ RCLASS_M_TBL(obj) = 0;
+ RCLASS_IV_INDEX_TBL(obj) = 0;
+ RCLASS_SET_SUPER((VALUE)obj, 0);
+ RCLASS_EXT(obj)->subclasses = NULL;
+ RCLASS_EXT(obj)->parent_subclasses = NULL;
+ RCLASS_EXT(obj)->module_subclasses = NULL;
+ */
+ RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj);
RCLASS_SERIAL(obj) = rb_next_class_serial();
-
RCLASS_REFINED_CLASS(obj) = Qnil;
RCLASS_EXT(obj)->allocator = 0;
+
return (VALUE)obj;
}
@@ -939,7 +940,7 @@ rb_prepend_module(VALUE klass, VALUE module)
OBJ_WB_UNPROTECT(origin); /* TODO: conservative shading. Need more survey. */
RCLASS_SET_SUPER(origin, RCLASS_SUPER(klass));
RCLASS_SET_SUPER(klass, origin);
- RB_OBJ_WRITE(klass, &RCLASS_ORIGIN(klass), origin);
+ RCLASS_SET_ORIGIN(klass, origin);
RCLASS_M_TBL(origin) = RCLASS_M_TBL(klass);
RCLASS_M_TBL_INIT(klass);
st_foreach(RCLASS_M_TBL(origin), move_refined_method,