summaryrefslogtreecommitdiff
path: root/string.c
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 /string.c
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 'string.c')
-rw-r--r--string.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/string.c b/string.c
index 97271827d3..72de7d26e2 100644
--- a/string.c
+++ b/string.c
@@ -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) {