ruby-changes:56852
From: nagachika <ko1@a...>
Date: Wed, 7 Aug 2019 21:04:14 +0900 (JST)
Subject: [ruby-changes:56852] nagachika: da36d5700d (ruby_2_6): merge revision(s) 53e9908d8afc7f03109b0aafd1698ab35f512b05: [Backport #15916]
https://git.ruby-lang.org/ruby.git/commit/?id=da36d5700d From da36d5700d9e0e66411d93595b6f654c85853fa1 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Wed, 7 Aug 2019 12:03:52 +0000 Subject: 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@g...> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e diff --git a/parse.y b/parse.y index 42f1a8f..473ae0e 100644 --- a/parse.y +++ b/parse.y @@ -8760,7 +8760,7 @@ gettable(struct parser_params *p, ID id, const YYLTYPE *loc) https://github.com/ruby/ruby/blob/trunk/parse.y#L8760 if (NIL_P(file)) file = rb_str_new(0, 0); else - file = rb_str_dup(file); + file = rb_str_dup(rb_fstring(file)); node = NEW_STR(add_mark_object(p, file), loc); } return node; diff --git a/string.c b/string.c index d0057b7..847533a 100644 --- a/string.c +++ b/string.c @@ -1164,6 +1164,13 @@ str_replace_shared_without_enc(VALUE str2, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L1164 } 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; diff --git a/version.h b/version.h index 8114f6b..0bd57f4 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1 #define RUBY_VERSION "2.6.3" #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 82 +#define RUBY_PATCHLEVEL 83 #define RUBY_RELEASE_YEAR 2019 #define RUBY_RELEASE_MONTH 8 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/