Permalink
Browse files

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent dfdb8b7 commit b39eabac5d206ee3249653cd2ec5c45bac27d860 normal committed Mar 9, 2014
Showing with 12 additions and 4 deletions.
  1. +8 −0 ChangeLog
  2. +4 −4 class.c
View
@@ -1,3 +1,11 @@
+Sun Mar 9 14:14:49 2014 Eric Wong <e@80x24.org>
+
+ * 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@ruby-lang.org>
* ext/fiddle/function.c (function_call): fix memory leak when an
View
@@ -42,7 +42,7 @@ rb_class_subclass_add(VALUE super, VALUE klass)
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 module, VALUE iclass)
{
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(VALUE klass)
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(VALUE klass)
RCLASS_EXT(entry->next->klass)->module_subclasses = RCLASS_EXT(klass)->module_subclasses;
}
- free(entry);
+ xfree(entry);
}
RCLASS_EXT(klass)->module_subclasses = NULL;

0 comments on commit b39eaba

Please sign in to comment.