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

ruby-changes:33223

From: normal <ko1@a...>
Date: Sun, 9 Mar 2014 14:22:04 +0900 (JST)
Subject: [ruby-changes:33223] normal:r45302 (trunk): class.c: check for malloc failures

normal	2014-03-09 14:22:01 +0900 (Sun, 09 Mar 2014)

  New Revision: 45302

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

  Log:
    class.c: check for malloc failures
    
    * class.c (rb_class_subclass_add): use xmalloc
    * class.c (rb_module_add_to_subclasses_list): ditto
    * class.c (rb_class_remove_from_super_subclasses): use xfree
    * class.c (rb_class_remove_from_module_subclasses): ditto
      [Bug #9616]
    
    xmalloc does OOM checking and helps GC accounting when used
    with xfree.

  Modified files:
    trunk/ChangeLog
    trunk/class.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45301)
+++ ChangeLog	(revision 45302)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Mar  9 14:14:49 2014  Eric Wong  <e@8...>
+
+	* class.c (rb_class_subclass_add): use xmalloc
+	* class.c (rb_module_add_to_subclasses_list): ditto
+	* class.c (rb_class_remove_from_super_subclasses): use xfree
+	* class.c (rb_class_remove_from_module_subclasses): ditto
+	  [Bug #9616]
+
 Sun Mar  9 13:51:16 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/fiddle/function.c (function_call): fix memory leak when an
Index: class.c
===================================================================
--- class.c	(revision 45301)
+++ class.c	(revision 45302)
@@ -42,7 +42,7 @@ rb_class_subclass_add(VALUE super, VALUE https://github.com/ruby/ruby/blob/trunk/class.c#L42
     rb_subclass_entry_t *entry, *head;
 
     if (super && super != Qundef) {
-	entry = malloc(sizeof(*entry));
+	entry = xmalloc(sizeof(*entry));
 	entry->klass = klass;
 	entry->next = NULL;
 
@@ -62,7 +62,7 @@ rb_module_add_to_subclasses_list(VALUE m https://github.com/ruby/ruby/blob/trunk/class.c#L62
 {
     rb_subclass_entry_t *entry, *head;
 
-    entry = malloc(sizeof(*entry));
+    entry = xmalloc(sizeof(*entry));
     entry->klass = iclass;
     entry->next = NULL;
 
@@ -88,7 +88,7 @@ rb_class_remove_from_super_subclasses(VA https://github.com/ruby/ruby/blob/trunk/class.c#L88
 	if (entry->next) {
 	    RCLASS_EXT(entry->next->klass)->parent_subclasses = RCLASS_EXT(klass)->parent_subclasses;
 	}
-	free(entry);
+	xfree(entry);
     }
 
     RCLASS_EXT(klass)->parent_subclasses = NULL;
@@ -107,7 +107,7 @@ rb_class_remove_from_module_subclasses(V https://github.com/ruby/ruby/blob/trunk/class.c#L107
 	    RCLASS_EXT(entry->next->klass)->module_subclasses = RCLASS_EXT(klass)->module_subclasses;
 	}
 
-	free(entry);
+	xfree(entry);
     }
 
     RCLASS_EXT(klass)->module_subclasses = NULL;

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

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