1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-07-05 01:51:51 +00:00
parent 033e8e5b61
commit 481292190f
3 changed files with 18 additions and 1 deletions

View file

@ -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

View file

@ -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));
}

View file

@ -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__