mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: potential memory leak
* string.c (rb_str_conv_enc_opts): allocate and hide wrapper before creating converter to be wrapped, to get rid of potential memory leak by failure on the allocation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
69d5f4ab53
commit
634779e62f
1 changed files with 2 additions and 1 deletions
3
string.c
3
string.c
|
@ -518,9 +518,10 @@ rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags,
|
|||
newstr = rb_str_new(0, len);
|
||||
olen = len;
|
||||
|
||||
econv_wrapper = rb_obj_alloc(rb_cEncodingConverter);
|
||||
RBASIC(econv_wrapper)->klass = 0;
|
||||
ec = rb_econv_open_opts(from->name, to->name, ecflags, ecopts);
|
||||
if (!ec) return str;
|
||||
econv_wrapper = rb_obj_alloc(rb_cEncodingConverter);
|
||||
DATA_PTR(econv_wrapper) = ec;
|
||||
|
||||
sp = (unsigned char*)RSTRING_PTR(str);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue