ruby-changes:32489
From: nobu <ko1@a...>
Date: Sun, 12 Jan 2014 16:41:18 +0900 (JST)
Subject: [ruby-changes:32489] nobu:r44568 (trunk): iseq.c: potential memory leak
nobu 2014-01-12 16:41:10 +0900 (Sun, 12 Jan 2014) New Revision: 44568 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44568 Log: iseq.c: potential memory leak * iseq.c (iseq_load): keep type_map to get rid of memory leak. based on a patch by Eric Wong at [ruby-core:59699]. [Bug #9399] Modified files: trunk/ChangeLog trunk/iseq.c trunk/ruby_atomic.h Index: ChangeLog =================================================================== --- ChangeLog (revision 44567) +++ ChangeLog (revision 44568) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Jan 12 16:41:10 2014 Nobuyoshi Nakada <nobu@r...> + + * iseq.c (iseq_load): keep type_map to get rid of memory leak. + based on a patch by Eric Wong at [ruby-core:59699]. [Bug #9399] + Sun Jan 12 09:21:35 2014 Nobuyoshi Nakada <nobu@r...> * include/ruby/util.h (DECIMAL_SIZE_OF_BITS): a preprocessor Index: iseq.c =================================================================== --- iseq.c (revision 44567) +++ iseq.c (revision 44568) @@ -484,6 +484,7 @@ iseq_load(VALUE self, VALUE data, VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L484 VALUE type, body, locals, args, exception; st_data_t iseq_type; + static struct st_table *type_map_cache = 0; struct st_table *type_map = 0; rb_iseq_t *iseq; rb_compile_option_t option; @@ -524,7 +525,9 @@ iseq_load(VALUE self, VALUE data, VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L525 iseq->self = iseqval; iseq->local_iseq = iseq; + type_map = type_map_cache; if (type_map == 0) { + struct st_table *cached_map; type_map = st_init_numtable(); st_insert(type_map, ID2SYM(rb_intern("top")), ISEQ_TYPE_TOP); st_insert(type_map, ID2SYM(rb_intern("method")), ISEQ_TYPE_METHOD); @@ -535,6 +538,11 @@ iseq_load(VALUE self, VALUE data, VALUE https://github.com/ruby/ruby/blob/trunk/iseq.c#L538 st_insert(type_map, ID2SYM(rb_intern("eval")), ISEQ_TYPE_EVAL); st_insert(type_map, ID2SYM(rb_intern("main")), ISEQ_TYPE_MAIN); st_insert(type_map, ID2SYM(rb_intern("defined_guard")), ISEQ_TYPE_DEFINED_GUARD); + cached_map = ATOMIC_PTR_CAS(type_map_cache, (struct st_table *)0, type_map); + if (cached_map) { + st_free_table(type_map); + type_map = cached_map; + } } if (st_lookup(type_map, type, &iseq_type) == 0) { Index: ruby_atomic.h =================================================================== --- ruby_atomic.h (revision 44567) +++ ruby_atomic.h (revision 44568) @@ -161,5 +161,10 @@ atomic_size_exchange(size_t *ptr, size_t https://github.com/ruby/ruby/blob/trunk/ruby_atomic.h#L161 # define ATOMIC_PTR_EXCHANGE(var, val) (void *)ATOMIC_SIZE_EXCHANGE(*(size_t *)&(var), (size_t)(val)) # endif #endif +#ifndef ATOMIC_PTR_CAS +# if SIZEOF_VOIDP == SIZEOF_SIZE_T +# define ATOMIC_PTR_CAS(var, oldval, val) (void *)ATOMIC_SIZE_CAS(*(size_t *)&(var), (size_t)(oldval), (size_t)(val)) +# endif +#endif #endif /* RUBY_ATOMIC_H */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/