diff options
-rw-r--r-- | string.c | 2 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 10 |
2 files changed, 11 insertions, 1 deletions
@@ -1734,7 +1734,7 @@ rb_str_init(int argc, VALUE *argv, VALUE str) const size_t osize = RSTRING(str)->as.heap.len + TERM_LEN(str); char *new_ptr = ALLOC_N(char, (size_t)capa + termlen); memcpy(new_ptr, old_ptr, osize < size ? osize : size); - FL_UNSET_RAW(str, STR_SHARED); + FL_UNSET_RAW(str, STR_SHARED|STR_NOFREE); RSTRING(str)->as.heap.ptr = new_ptr; } else if (STR_HEAP_SIZE(str) != (size_t)capa + termlen) { 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]) |