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

ruby-changes:30884

From: nobu <ko1@a...>
Date: Wed, 18 Sep 2013 16:32:25 +0900 (JST)
Subject: [ruby-changes:30884] nobu:r42963 (trunk): proc.c: allocate wrapper object first

nobu	2013-09-18 16:32:17 +0900 (Wed, 18 Sep 2013)

  New Revision: 42963

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

  Log:
    proc.c: allocate wrapper object first
    
    * proc.c (mnew_from_me): allocate structs after allocated wrapper
      object successfully, to get rid of potential memory leak.

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42962)
+++ ChangeLog	(revision 42963)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Sep 18 16:32:15 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (mnew_from_me): allocate structs after allocated wrapper
+	  object successfully, to get rid of potential memory leak.
+
 Tue Sep 17 15:54:03 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/shell/command-processor.rb (Shell::CommandProcessor#find_system_command):
Index: proc.c
===================================================================
--- proc.c	(revision 42962)
+++ proc.c	(revision 42963)
@@ -1125,7 +1125,6 @@ mnew_from_me(rb_method_entry_t *me, VALU https://github.com/ruby/ruby/blob/trunk/proc.c#L1125
     VALUE rclass = klass;
     ID rid = id;
     struct METHOD *data;
-    rb_method_entry_t meb;
     rb_method_definition_t *def = 0;
     rb_method_flag_t flag = NOEX_UNDEF;
 
@@ -1136,18 +1135,7 @@ mnew_from_me(rb_method_entry_t *me, VALU https://github.com/ruby/ruby/blob/trunk/proc.c#L1135
 
 	if (obj != Qundef && !rb_method_basic_definition_p(klass, rmiss)) {
 	    if (RTEST(rb_funcall(obj, rmiss, 2, sym, scope ? Qfalse : Qtrue))) {
-		def = ALLOC(rb_method_definition_t);
-		def->type = VM_METHOD_TYPE_MISSING;
-		def->original_id = id;
-		def->alias_count = 0;
-
-		meb.flag = 0;
-		meb.mark = 0;
-		meb.called_id = id;
-		meb.klass = klass;
-		meb.def = def;
-		me = &meb;
-		def = 0;
+		me = 0;
 
 		goto gen_method;
 	    }
@@ -1196,9 +1184,27 @@ mnew_from_me(rb_method_entry_t *me, VALU https://github.com/ruby/ruby/blob/trunk/proc.c#L1184
     data->defined_class = defined_class;
     data->id = rid;
     data->me = ALLOC(rb_method_entry_t);
-    *data->me = *me;
-    data->me->def->alias_count++;
+    if (me) {
+	*data->me = *me;
+    }
+    else {
+	me = data->me;
+	me->flag = 0;
+	me->mark = 0;
+	me->called_id = id;
+	me->klass = klass;
+	me->def = 0;
+
+	def = ALLOC(rb_method_definition_t);
+	me->def = def;
+
+	def->type = VM_METHOD_TYPE_MISSING;
+	def->original_id = id;
+	def->alias_count = 0;
+
+    }
     data->ume = ALLOC(struct unlinked_method_entry_list_entry);
+    data->me->def->alias_count++;
 
     OBJ_INFECT(method, klass);
 

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

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