string.c: fstring must not be a shared string

* string.c (fstr_update_callback): fstring must not be a shared
  string, or the content without RSTRING_FSTR may be freed.
  [ruby-dev:49188] [Bug #11386]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-07-24 12:27:32 +00:00
parent 6f8d3709da
commit b706810232
2 changed files with 12 additions and 4 deletions

View File

@ -1,3 +1,9 @@
Fri Jul 24 21:27:29 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (fstr_update_callback): fstring must not be a shared
string, or the content without RSTRING_FSTR may be freed.
[ruby-dev:49188] [Bug #11386]
Fri Jul 24 20:09:43 2015 Naohisa Goto <ngotogenome@gmail.com>
* test/rinda/test_rinda.rb (RingIPv6#prepare_ipv6): prevent to use

View File

@ -266,8 +266,7 @@ fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existi
assert(OBJ_FROZEN(str));
}
if (!BARE_STRING_P(str)) {
str = str_new_shared(rb_cString, str);
OBJ_FREEZE_RAW(str);
str = str_new_frozen(rb_cString, str);
}
}
RBASIC(str)->flags |= RSTRING_FSTR;
@ -1002,9 +1001,13 @@ rb_str_new_shared(VALUE str)
VALUE
rb_str_new_frozen(VALUE orig)
{
VALUE str;
if (OBJ_FROZEN(orig)) return orig;
return str_new_frozen(rb_obj_class(orig), orig);
str = str_new_frozen(rb_obj_class(orig), orig);
OBJ_INFECT(str, orig);
return str;
}
static VALUE
@ -1048,7 +1051,6 @@ str_new_frozen(VALUE klass, VALUE orig)
}
rb_enc_cr_str_exact_copy(str, orig);
OBJ_INFECT(str, orig);
OBJ_FREEZE(str);
return str;
}