mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 07:26:00 +02:00
[Bug #18154] Fix memory leak in String#initialize
String#initialize can leak memory when called on a string that is marked with STR_NOFREE because it does not unset the STR_NOFREE flag.
This commit is contained in:
parent
0b9242ffac
commit
5d81554281
Notes:
git
2021-09-08 23:20:38 +09:00
2 changed files with 11 additions and 1 deletions
|
@ -105,6 +105,16 @@ PREP
|
|||
CODE
|
||||
end
|
||||
|
||||
# Bug #18154
|
||||
def test_initialize_nofree_memory_leak
|
||||
assert_no_memory_leak([], <<-PREP, <<-CODE, rss: true)
|
||||
code = proc {0.to_s.__send__(:initialize, capacity: 10000)}
|
||||
1_000.times(&code)
|
||||
PREP
|
||||
100_000.times(&code)
|
||||
CODE
|
||||
end
|
||||
|
||||
def test_AREF # '[]'
|
||||
assert_equal("A", S("AooBar")[0])
|
||||
assert_equal("B", S("FooBaB")[-1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue