From cb54008be67547866fa7a552a3eff5059d34c1b3 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 16 May 2015 12:56:29 +0000 Subject: wrapper object before alloc * error.c (rb_name_err_mesg_new): new wrapper object before allocate data area and get rid of potential memory leak. GC guards are no longer needed. * file.c (stat_new_0): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'file.c') diff --git a/file.c b/file.c index c724a4b97c..ac99de6043 100644 --- a/file.c +++ b/file.c @@ -406,12 +406,14 @@ static VALUE stat_new_0(VALUE klass, const struct stat *st) { struct stat *nst = 0; + VALUE obj = TypedData_Wrap_Struct(klass, &stat_data_type, 0); if (st) { nst = ALLOC(struct stat); *nst = *st; + RTYPEDDATA_DATA(obj) = nst; } - return TypedData_Wrap_Struct(klass, &stat_data_type, nst); + return obj; } VALUE -- cgit v1.2.3