diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-04 19:10:03 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-02-04 19:10:03 +0000 |
commit | 18eef0b9beabf6e332afcc1ac9f8edaabc343560 (patch) | |
tree | 48c67fe87db28cd7c8369762d45d91bc8551408f | |
parent | 6ae6a8c7bc86e9740850e64125deceb7d8a01fce (diff) | |
download | ruby-18eef0b9beabf6e332afcc1ac9f8edaabc343560.tar.gz |
* vm_eval.c: Fix symbol leak with non optimized +send+ and method_missing [#10828]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/ruby/test_symbol.rb | 29 | ||||
-rw-r--r-- | vm_eval.c | 8 |
2 files changed, 34 insertions, 3 deletions
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 5d2e2c3267..d1a4cec532 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -274,4 +274,33 @@ class TestSymbol < Test::Unit::TestCase 10.times { |i| x.send "send should not leak #{i} - sym mm".to_sym } end end + + def test_symbol_send_leak_string_no_optimization + assert_no_immortal_symbol_created do + 10.times { 42.method(:send).call "send should not leak #{i} - str slow" rescue nil } + end + end + + def test_symbol_send_leak_symbol_no_optimization + assert_no_immortal_symbol_created do + 10.times { 42.method(:send).call "send should not leak #{i} - sym slow".to_sym rescue nil } + end + end + + def test_symbol_send_leak_string_custom_method_missing_no_optimization + x = Object.new + def x.method_missing(*); end + assert_no_immortal_symbol_created do + 10.times { |i| x.method(:send).call "send should not leak #{i} - str mm slow" } + end + end + + def test_symbol_send_leak_symbol_custom_method_missing_no_optimization + x = Object.new + def x.method_missing(*); end + assert_no_immortal_symbol_created do + 10.times { |i| x.method(:send).call "send should not leak #{i} - sym mm slow".to_sym } + end + end + end @@ -884,16 +884,18 @@ send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope) rb_raise(rb_eArgError, "no method name given"); } - vid = *argv++; argc--; + vid = *argv; id = rb_check_id(&vid); if (!id) { if (rb_method_basic_definition_p(CLASS_OF(recv), idMethodMissing)) { VALUE exc = make_no_method_exception(rb_eNoMethodError, NULL, - recv, ++argc, --argv); + recv, argc, argv); rb_exc_raise(exc); } - id = rb_to_id(vid); + id = idMethodMissing; + } else { + argv++; argc--; } PASS_PASSED_BLOCK_TH(th); return rb_call0(recv, id, argc, argv, scope, self); |