diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-11 09:15:20 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-03-11 09:15:20 +0000 |
commit | 5922c954614e5947a548780bb3b894626affe6dd (patch) | |
tree | c7de7025f8d3dbeb816aa99cd197e5adba33815e /internal.h | |
parent | 5a62fdee4d166fe0eff14bc616e1befa8ad54cd2 (diff) | |
download | ruby-5922c954614e5947a548780bb3b894626affe6dd.tar.gz |
* 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 'internal.h')
-rw-r--r-- | internal.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/internal.h b/internal.h index 0aa58439b5..372cf5daba 100644 --- a/internal.h +++ b/internal.h @@ -311,7 +311,7 @@ struct rb_classext_struct { */ rb_subclass_entry_t **module_subclasses; rb_serial_t class_serial; - VALUE origin; + const VALUE origin_; VALUE refined_class; rb_alloc_func_t allocator; }; @@ -477,10 +477,19 @@ void rb_class_remove_from_super_subclasses(VALUE); #define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl) #define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl) #define RCLASS_IV_INDEX_TBL(c) (RCLASS_EXT(c)->iv_index_tbl) -#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin) +#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_) #define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class) #define RCLASS_SERIAL(c) (RCLASS_EXT(c)->class_serial) +#define RICLASS_IS_ORIGIN FL_USER5 + +static inline void +RCLASS_SET_ORIGIN(VALUE klass, VALUE origin) +{ + RB_OBJ_WRITE(klass, &RCLASS_ORIGIN(klass), origin); + if (klass != origin) FL_SET(origin, RICLASS_IS_ORIGIN); +} + static inline void RCLASS_M_TBL_INIT(VALUE c) { |