summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-04 19:03:20 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-02-04 19:03:20 +0000
commit6ae6a8c7bc86e9740850e64125deceb7d8a01fce (patch)
treeb29246b2a5fa032c7f81402ba98bd30bf881f4ba
parent454f89e2ea99044590f7be1e9a9993cd9689f8cd (diff)
* vm_insnhelper.c: Fix symbol leak with +send+ and method_missing [#10828]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--test/ruby/test_symbol.rb16
-rw-r--r--vm_insnhelper.c17
3 files changed, 29 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 8b1c4a3..b9537b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Thu Feb 5 03:59:33 2015 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
+
+ * vm_insnhelper.c: Fix symbol leak with +send+ [Bug #10828]
+
Wed Feb 4 20:26:54 2015 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (Init_win32ole): should not use atexit to
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index db0d135..5d2e2c3 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -258,4 +258,20 @@ class TestSymbol < Test::Unit::TestCase
10.times { 42.send "send should not leak #{i} - sym".to_sym rescue nil }
end
end
+
+ def test_symbol_send_leak_string_custom_method_missing
+ x = Object.new
+ def x.method_missing(*); end
+ assert_no_immortal_symbol_created do
+ 10.times { |i| x.send "send should not leak #{i} - str mm" }
+ end
+ end
+
+ def test_symbol_send_leak_symbol_custom_method_missing
+ x = Object.new
+ def x.method_missing(*); end
+ assert_no_immortal_symbol_created do
+ 10.times { |i| x.send "send should not leak #{i} - sym mm".to_sym }
+ end
+ end
end
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 84c2ca2..a65ba91 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1531,16 +1531,17 @@ vm_call_opt_send(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *c
VALUE exc = make_no_method_exception(rb_eNoMethodError, NULL, ci->recv, rb_long2int(ci->argc), &TOPN(i));
rb_exc_raise(exc);
}
- ci->mid = rb_to_id(sym);
- }
-
- /* shift arguments */
- if (i > 0) {
- MEMMOVE(&TOPN(i), &TOPN(i-1), VALUE, i);
+ ci->mid = idMethodMissing;
+ th->method_missing_reason = ci->aux.missing_reason = NOEX_VCALL;
+ } else {
+ /* shift arguments */
+ if (i > 0) {
+ MEMMOVE(&TOPN(i), &TOPN(i-1), VALUE, i);
+ }
+ ci->argc -= 1;
+ DEC_SP(1);
}
ci->me = rb_method_entry_without_refinements(CLASS_OF(ci->recv), ci->mid, &ci->defined_class);
- ci->argc -= 1;
- DEC_SP(1);
ci->flag = VM_CALL_FCALL | VM_CALL_OPT_SEND;