Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
* string.c (str_make_independent_expand): free independent buffer.
  [Bug# 15935]

Co-Authored-By: luke-gru (Luke Gruber) <luke.gru@gmail.com>
  • Loading branch information
nobu and luke-gru committed Jun 18, 2019
1 parent c770c98 commit 8b3774b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion string.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 8b3774b

Please sign in to comment.