Get rid of indirect sharing

* string.c (str_duplicate): share the root shared string if the
  original string is already sharing, so that all shared strings
  refer the root shared string directly.  indirect sharing can
  cause a dangling pointer.

[Bug #15792]
This commit is contained in:
Nobuyoshi Nakada 2019-04-27 21:21:55 +09:00
parent afb361dfd0
commit 3f9562015e
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 17 additions and 3 deletions

View file

@ -2961,6 +2961,15 @@ CODE
end
=end
def test_nesting_shared
a = ('a' * 24).encode(Encoding::ASCII).gsub('x', '')
hash = {}
hash[a] = true
assert_equal(('a' * 24), a)
4.times { GC.start }
assert_equal(('a' * 24), a, '[Bug #15792]')
end
def test_shared_force_encoding
s = "\u{3066}\u{3059}\u{3068}".gsub(//, '')
h = {}