diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-08-07 12:03:52 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-08-07 12:03:52 +0000 |
commit | da36d5700d9e0e66411d93595b6f654c85853fa1 (patch) | |
tree | 6ab1d2e1a8412d93c3819ee2b6c955139bdeadaf /string.c | |
parent | f5930c87174c369eaad42523ffd0f3cb8ff15b8a (diff) |
merge revision(s) 53e9908d8afc7f03109b0aafd1698ab35f512b05: [Backport #15916]
Fix memory leak
* string.c (str_replace_shared_without_enc): free previous buffer
before replaced.
* parse.y (gettable): make sure in advance that the `__FILE__`
object shares a fstring, to get rid of replacement with the
fstring later.
TODO: this hack may be needed in other places.
[Bug #15916]
Co-Authored-By: luke-gru (Luke Gruber) <luke.gru@gmail.com>
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -1164,6 +1164,13 @@ str_replace_shared_without_enc(VALUE str2, VALUE str) } else { str = rb_str_new_frozen(str); + if (!STR_EMBED_P(str2) && !FL_TEST_RAW(str2, STR_SHARED|STR_NOFREE)) { + /* TODO: check if str2 is a shared root */ + char *ptr2 = STR_HEAP_PTR(str2); + if (STR_HEAP_PTR(str) != ptr2) { + ruby_sized_xfree(ptr2, STR_HEAP_SIZE(str2)); + } + } FL_SET(str2, STR_NOEMBED); RSTRING_GETMEM(str, ptr, len); RSTRING(str2)->as.heap.len = len; |