summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2021-09-07 14:06:42 -0400
committerPeter Zhu <peter@peterzhu.ca>2021-09-08 10:20:12 -0400
commit5d815542815fe8b939239750bba7f8f0b79c97d6 (patch)
treec17d920614e9bc8e6c5d732757ed6bad7d965695 /test
parent0b9242ffacd92fe02e640efb8640041e6838cb8b (diff)
[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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4814
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_string.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index e1a957eebf..12e4b0fe2a 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -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])