summaryrefslogtreecommitdiff
path: root/proc.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 07:32:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 07:32:17 +0000
commit61d79504c98669ac8243be5b1b4a35840ca3831c (patch)
tree96e7c883858ce55f4043f4b2b7927c38bb8b51f9 /proc.c
parentb56fbb9b121665ab54e3bc1b9b77d5ad3a351e4f (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'proc.c')
-rw-r--r--proc.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/proc.c b/proc.c
index 2db2f773f4..29c79d9dc6 100644
--- a/proc.c
+++ b/proc.c
@@ -1125,7 +1125,6 @@ mnew_from_me(rb_method_entry_t *me, VALUE defined_class, VALUE klass,
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, VALUE defined_class, VALUE klass,
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, VALUE defined_class, VALUE klass,
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);