summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--iseq.c8
-rw-r--r--ruby_atomic.h12
-rw-r--r--version.h2
4 files changed, 25 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e78d251fa9..e0846b9114 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Feb 14 15:40:32 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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]
+
Fri Feb 14 15:25:23 2014 Tanaka Akira <akr@fsij.org>
* lib/resolv.rb (Resolv::DNS::Resource::TXT#data): Return concatenated
diff --git a/iseq.c b/iseq.c
index 721277a7d3..f680e60839 100644
--- a/iseq.c
+++ b/iseq.c
@@ -450,6 +450,7 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
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;
@@ -488,7 +489,9 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
GetISeqPtr(iseqval, iseq);
iseq->self = iseqval;
+ 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);
@@ -499,6 +502,11 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
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) {
diff --git a/ruby_atomic.h b/ruby_atomic.h
index a811587cc3..548adee347 100644
--- a/ruby_atomic.h
+++ b/ruby_atomic.h
@@ -56,6 +56,7 @@ rb_w32_atomic_or(volatile rb_atomic_t *var, rb_atomic_t val)
# define ATOMIC_SIZE_INC(var) InterlockedIncrement64(&(var))
# define ATOMIC_SIZE_DEC(var) InterlockedDecrement64(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) InterlockedExchange64(&(var), (val))
+# define ATOMIC_SIZE_CAS(var, oldval, val) InterlockedCompareExchange64(&(var), (oldval), (val))
# else
# define ATOMIC_SIZE_ADD(var, val) InterlockedExchangeAdd((LONG *)&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) InterlockedExchangeAdd((LONG *)&(var), -(val))
@@ -80,7 +81,7 @@ typedef unsigned int rb_atomic_t;
# define ATOMIC_SIZE_INC(var) atomic_inc_ulong(&(var))
# define ATOMIC_SIZE_DEC(var) atomic_dec_ulong(&(var))
# define ATOMIC_SIZE_EXCHANGE(var, val) atomic_swap_ulong(&(var), (val))
-# else
+# define ATOMIC_SIZE_CAS(var, oldval, val) atomic_cas_ulong(&(var), (oldval), (# else
# define ATOMIC_SIZE_ADD(var, val) atomic_add_int(&(var), (val))
# define ATOMIC_SIZE_SUB(var, val) atomic_add_int(&(var), -(val))
# define ATOMIC_SIZE_INC(var) atomic_inc_uint(&(var))
@@ -113,10 +114,19 @@ atomic_size_exchange(size_t *ptr, size_t val)
}
#endif
+#ifndef ATOMIC_SIZE_CAS
+# define ATOMIC_SIZE_CAS(var, oldval, val) ATOMIC_CAS(var, oldval, val)
+#endif
+
#ifndef ATOMIC_PTR_EXCHANGE
# if SIZEOF_VOIDP == SIZEOF_SIZE_T
# 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 */
diff --git a/version.h b/version.h
index bcd269861e..a4f54f6ff5 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 526
+#define RUBY_PATCHLEVEL 527
#define RUBY_RELEASE_DATE "2014-02-14"
#define RUBY_RELEASE_YEAR 2014