summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-22 04:35:18 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-22 04:35:18 +0000
commit276b6b82c3d5ce0204454c7dbd9d25cf1d05b322 (patch)
treefa415fa742cce20ff3b0b31e9150d27dcfa05507
parentdf382466acdaed86dddd102c9c2d827622869db0 (diff)
downloadruby-276b6b82c3d5ce0204454c7dbd9d25cf1d05b322.tar.gz
merge revision(s) 44568: [Backport #9399]
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45105 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--iseq.c8
-rw-r--r--ruby_atomic.h5
-rw-r--r--version.h2
4 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 9323ed5ae5..5ccf2fc5bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Feb 22 13:26:57 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]
+
Sat Feb 22 13:17:32 2014 Masaki Matsushita <glass.saga@gmail.com>
* ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
diff --git a/iseq.c b/iseq.c
index 679bdb7a2d..22081a1ee2 100644
--- a/iseq.c
+++ b/iseq.c
@@ -483,6 +483,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;
@@ -523,7 +524,9 @@ iseq_load(VALUE self, VALUE data, VALUE parent, VALUE opt)
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);
@@ -534,6 +537,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 69efbdc4c4..789efdc4ea 100644
--- a/ruby_atomic.h
+++ b/ruby_atomic.h
@@ -161,5 +161,10 @@ atomic_size_exchange(size_t *ptr, size_t val)
# 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 2bb33993f5..d1b63ae75b 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.1.1"
#define RUBY_RELEASE_DATE "2014-02-22"
-#define RUBY_PATCHLEVEL 51
+#define RUBY_PATCHLEVEL 52
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 2