[前][次][番号順一覧][スレッド一覧]

ruby-changes:37419

From: marcandre <ko1@a...>
Date: Thu, 5 Feb 2015 04:03:41 +0900 (JST)
Subject: [ruby-changes:37419] marcandRe: r49500 (trunk): * vm_insnhelper.c: Fix symbol leak with +send+ and method_missing [#10828]

marcandre	2015-02-05 04:03:20 +0900 (Thu, 05 Feb 2015)

  New Revision: 49500

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49500

  Log:
    * vm_insnhelper.c: Fix symbol leak with +send+ and method_missing [#10828]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_symbol.rb
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49499)
+++ ChangeLog	(revision 49500)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb  5 03:59:33 2015  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* vm_insnhelper.c: Fix symbol leak with +send+ [Bug #10828]
+
 Wed Feb  4 20:26:54 2015  Masaki Suketa <masaki.suketa@n...>
 
 	* ext/win32ole/win32ole.c (Init_win32ole): should not use atexit to
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 49499)
+++ vm_insnhelper.c	(revision 49500)
@@ -1531,16 +1531,17 @@ vm_call_opt_send(rb_thread_t *th, rb_con https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1531
 	    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;
 
Index: test/ruby/test_symbol.rb
===================================================================
--- test/ruby/test_symbol.rb	(revision 49499)
+++ test/ruby/test_symbol.rb	(revision 49500)
@@ -258,4 +258,20 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L258
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]