1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2013-09-18 07:32:17 +00:00
parent b56fbb9b12
commit 61d79504c9
2 changed files with 26 additions and 15 deletions

View file

@ -1,3 +1,8 @@
Wed Sep 18 16:32:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* lib/shell/command-processor.rb (Shell::CommandProcessor#find_system_command):

36
proc.c
View file

@ -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);