[前][次][番号順一覧][スレッド一覧]

ruby-changes:38429

From: nobu <ko1@a...>
Date: Sat, 16 May 2015 21:56:46 +0900 (JST)
Subject: [ruby-changes:38429] nobu:r50510 (trunk): wrapper object before alloc

nobu	2015-05-16 21:56:29 +0900 (Sat, 16 May 2015)

  New Revision: 50510

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50510

  Log:
    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.

  Modified files:
    trunk/error.c
    trunk/file.c
Index: error.c
===================================================================
--- error.c	(revision 50509)
+++ error.c	(revision 50510)
@@ -1155,16 +1155,13 @@ static const rb_data_type_t name_err_mes https://github.com/ruby/ruby/blob/trunk/error.c#L1155
 VALUE
 rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
 {
+    VALUE result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, 0);
     VALUE *ptr = ALLOC_N(VALUE, NAME_ERR_MESG_COUNT);
-    VALUE result;
 
     ptr[0] = mesg;
     ptr[1] = recv;
     ptr[2] = method;
-    result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, ptr);
-    RB_GC_GUARD(mesg);
-    RB_GC_GUARD(recv);
-    RB_GC_GUARD(method);
+    RTYPEDDATA_DATA(result) = ptr;
     return result;
 }
 
Index: file.c
===================================================================
--- file.c	(revision 50509)
+++ file.c	(revision 50510)
@@ -406,12 +406,14 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/file.c#L406
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]