From 634779e62fac7154657cf73990fe7caafe1c2a21 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 21 Mar 2013 05:13:59 +0000 Subject: 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 --- string.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'string.c') diff --git a/string.c b/string.c index 417cfac54d..80869bd720 100644 --- a/string.c +++ b/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); -- cgit v1.2.3