summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-04 19:03:04 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-04 19:03:04 +0000
commit454f89e2ea99044590f7be1e9a9993cd9689f8cd (patch)
tree98c5305a2347af2bbf64fbfa755f39b642afa736
parent8350b7dc04ad2af3473c91e680ca05a140243101 (diff)
* vm_insnhelper.c: Fix one type of symbol leak with +send+
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_symbol.rb20
-rw-r--r--vm_insnhelper.c5
2 files changed, 21 insertions, 4 deletions
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index 596f2b0..db0d135 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -238,4 +238,24 @@ class TestSymbol < Test::Unit::TestCase
200_000.times { |i| i.to_s.to_sym }
end;
end
+
+ def assert_no_immortal_symbol_created
+ delta = -Symbol.all_symbols.size
+ yield
+ GC.start
+ delta += Symbol.all_symbols.size
+ assert_equal 0, delta, "#{delta} immortal symbols were created"
+ end
+
+ def test_symbol_send_leak_string
+ assert_no_immortal_symbol_created do
+ 10.times { 42.send "send should not leak #{i} - str" rescue nil }
+ end
+ end
+
+ def test_symbol_send_leak_symbol
+ assert_no_immortal_symbol_created do
+ 10.times { 42.send "send should not leak #{i} - sym".to_sym rescue nil }
+ end
+ end
end
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index c1c4e3f2..84c2ca2 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1526,10 +1526,7 @@ vm_call_opt_send(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *c
sym = TOPN(i);
- if (SYMBOL_P(sym)) {
- ci->mid = SYM2ID(sym);
- }
- else if (!(ci->mid = rb_check_id(&sym))) {
+ if (!(ci->mid = rb_check_id(&sym))) {
if (rb_method_basic_definition_p(CLASS_OF(ci->recv), idMethodMissing)) {
VALUE exc = make_no_method_exception(rb_eNoMethodError, NULL, ci->recv, rb_long2int(ci->argc), &TOPN(i));
rb_exc_raise(exc);