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

ruby-changes:39066

From: nobu <ko1@a...>
Date: Sun, 5 Jul 2015 10:52:02 +0900 (JST)
Subject: [ruby-changes:39066] nobu:r51147 (trunk): array.c: fix memory leak

nobu	2015-07-05 10:51:51 +0900 (Sun, 05 Jul 2015)

  New Revision: 51147

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

  Log:
    array.c: fix memory leak
    
    * array.c (rb_ary_sort_bang): the original array may not be
      embedded even if a substitution array is embedded, as it is
      embedded when the original array is short enough but not
      embedded.  [ruby-dev:49166] [Bug #11332]

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/test/ruby/test_array.rb
Index: array.c
===================================================================
--- array.c	(revision 51146)
+++ array.c	(revision 51147)
@@ -2479,8 +2479,8 @@ rb_ary_sort_bang(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2479
         if (ARY_EMBED_P(tmp)) {
             if (ARY_SHARED_P(ary)) { /* ary might be destructively operated in the given block */
                 rb_ary_unshare(ary);
+		FL_SET_EMBED(ary);
             }
-            FL_SET_EMBED(ary);
 	    ary_memcpy(ary, 0, ARY_EMBED_LEN(tmp), ARY_EMBED_PTR(tmp));
             ARY_SET_LEN(ary, ARY_EMBED_LEN(tmp));
         }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51146)
+++ ChangeLog	(revision 51147)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jul  5 10:51:48 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* array.c (rb_ary_sort_bang): the original array may not be
+	  embedded even if a substitution array is embedded, as it is
+	  embedded when the original array is short enough but not
+	  embedded.  [ruby-dev:49166] [Bug #11332]
+
 Sun Jul  5 09:31:40 2015  Eric Wong  <e@8...>
 
 	* test/ruby/test_process.rb: test for fd=3 usability in child
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 51146)
+++ test/ruby/test_array.rb	(revision 51147)
@@ -1445,6 +1445,16 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L1445
     assert_equal(orig, ary, "must not be modified once frozen")
   end
 
+  def test_short_heap_array_sort_bang_memory_leak
+    bug11332 = '[ruby-dev:49166] [Bug #11332]'
+    assert_no_memory_leak([], <<-PREP, <<-TEST, bug11332, limit: 1.20)
+      def t; ary = [*1..5]; ary.pop(2); ary.sort!; end
+      1.times {t}
+    PREP
+      500000.times {t}
+    TEST
+  end
+
   def test_to_a
     a = @cls[ 1, 2, 3 ]
     a_id = a.__id__

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

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