aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--array.c2
-rw-r--r--test/ruby/test_array.rb10
3 files changed, 18 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 977fb57b65..bfe1b835bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Sun Jul 5 10:51:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@80x24.org>
* test/ruby/test_process.rb: test for fd=3 usability in child
diff --git a/array.c b/array.c
index 5953dfcaf8..132528d2e1 100644
--- a/array.c
+++ b/array.c
@@ -2479,8 +2479,8 @@ rb_ary_sort_bang(VALUE ary)
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));
}
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index f6d0d3d434..51caf8fa37 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1445,6 +1445,16 @@ class TestArray < Test::Unit::TestCase
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__