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:
parent
c770c98ac4
commit
8b3774be3d
1 changed files with 4 additions and 1 deletions
5
string.c
5
string.c
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue