1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix memory leak

* string.c (str_make_independent_expand): free independent buffer.
  [Bug# 15935]

Co-Authored-By: luke-gru (Luke Gruber) <luke.gru@gmail.com>
This commit is contained in:
Nobuyoshi Nakada 2019-06-18 13:27:05 +09:00
parent c770c98ac4
commit 8b3774be3d
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60

View file

@ -2069,7 +2069,7 @@ static void
str_make_independent_expand(VALUE str, long len, long expand, const int termlen)
{
char *ptr;
const char *oldptr;
char *oldptr;
long capa = len + expand;
if (len > capa) len = capa;
@ -2088,6 +2088,9 @@ str_make_independent_expand(VALUE str, long len, long expand, const int termlen)
if (oldptr) {
memcpy(ptr, oldptr, len);
}
if (FL_TEST_RAW(str, STR_NOEMBED|STR_NOFREE|STR_SHARED) == STR_NOEMBED) {
xfree(oldptr);
}
STR_SET_NOEMBED(str);
FL_UNSET(str, STR_SHARED|STR_NOFREE);
TERM_FILL(ptr + len, termlen);