diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-08 13:30:04 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-08 13:30:04 +0000 |
commit | 4e39dc864cc197923bf6e56b9359a1c4def7b1ae (patch) | |
tree | 23207320fc8686084ac145a122a217875fcc00cc /string.c | |
parent | 9a57bc8f55116d02c8294dcb4ebcddcfd56a006f (diff) |
* string.c (rb_str_modify_expand): fix memory leak.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -1328,12 +1328,20 @@ rb_str_modify_expand(VALUE str, long expand) if (expand < 0) { rb_raise(rb_eArgError, "negative expanding string size"); } - if (!str_independent(str) || - (expand > 0 && - (!STR_EMBED_P(str) || - RSTRING_LEN(str) + expand > RSTRING_EMBED_LEN_MAX))) { + if (!str_independent(str)) { str_make_independent_expand(str, expand); } + else if (expand > 0) { + long len = RSTRING_LEN(str); + long capa = len + expand; + if (!STR_EMBED_P(str)) { + REALLOC_N(RSTRING(str)->as.heap.ptr, char, capa+1); + RSTRING(str)->as.heap.aux.capa = capa; + } + else if (capa > RSTRING_EMBED_LEN_MAX) { + str_make_independent_expand(str, expand); + } + } ENC_CODERANGE_CLEAR(str); } |