mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_modify_expand): fix memory leak.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
54b90b7be8
commit
83c7d9df2b
4 changed files with 25 additions and 4 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Wed Feb 8 22:29:59 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_modify_expand): fix memory leak.
|
||||||
|
|
||||||
Wed Feb 8 14:06:59 2012 Hiroshi Nakamura <nahi@ruby-lang.org>
|
Wed Feb 8 14:06:59 2012 Hiroshi Nakamura <nahi@ruby-lang.org>
|
||||||
|
|
||||||
* ext/openssl/ossl_ssl.c: Add SSL constants and allow to unset SSL
|
* ext/openssl/ossl_ssl.c: Add SSL constants and allow to unset SSL
|
||||||
|
|
|
@ -7,8 +7,16 @@ bug_str_modify(VALUE str)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
bug_str_modify_expand(VALUE str, VALUE expand)
|
||||||
|
{
|
||||||
|
rb_str_modify_expand(str, NUM2LONG(expand));
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Init_modify(VALUE klass)
|
Init_modify(VALUE klass)
|
||||||
{
|
{
|
||||||
rb_define_method(klass, "modify!", bug_str_modify, 0);
|
rb_define_method(klass, "modify!", bug_str_modify, 0);
|
||||||
|
rb_define_method(klass, "modify_expand!", bug_str_modify_expand, 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -712,6 +712,7 @@ long rb_str_sublen(VALUE, long);
|
||||||
VALUE rb_str_substr(VALUE, long, long);
|
VALUE rb_str_substr(VALUE, long, long);
|
||||||
VALUE rb_str_subseq(VALUE, long, long);
|
VALUE rb_str_subseq(VALUE, long, long);
|
||||||
void rb_str_modify(VALUE);
|
void rb_str_modify(VALUE);
|
||||||
|
void rb_str_modify_expand(VALUE, long);
|
||||||
VALUE rb_str_freeze(VALUE);
|
VALUE rb_str_freeze(VALUE);
|
||||||
void rb_str_set_len(VALUE, long);
|
void rb_str_set_len(VALUE, long);
|
||||||
VALUE rb_str_resize(VALUE, long);
|
VALUE rb_str_resize(VALUE, long);
|
||||||
|
|
16
string.c
16
string.c
|
@ -1328,12 +1328,20 @@ rb_str_modify_expand(VALUE str, long expand)
|
||||||
if (expand < 0) {
|
if (expand < 0) {
|
||||||
rb_raise(rb_eArgError, "negative expanding string size");
|
rb_raise(rb_eArgError, "negative expanding string size");
|
||||||
}
|
}
|
||||||
if (!str_independent(str) ||
|
if (!str_independent(str)) {
|
||||||
(expand > 0 &&
|
|
||||||
(!STR_EMBED_P(str) ||
|
|
||||||
RSTRING_LEN(str) + expand > RSTRING_EMBED_LEN_MAX))) {
|
|
||||||
str_make_independent_expand(str, expand);
|
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);
|
ENC_CODERANGE_CLEAR(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue