mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
proc.c, vm.c: fix possible memory leak
* proc.c (proc_binding): fix possible memory leak of rb_env_t when TypedData_Wrap_Struct failed. * vm.c (vm_make_env_each): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50463 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f5299e93a7
commit
3875df97f1
2 changed files with 5 additions and 5 deletions
7
proc.c
7
proc.c
|
@ -2510,16 +2510,15 @@ proc_binding(VALUE self)
|
|||
if (iseq && env->local_size < iseq->local_size) {
|
||||
int prev_local_size = env->local_size;
|
||||
int local_size = iseq->local_size;
|
||||
rb_env_t *newenv;
|
||||
VALUE newenvval;
|
||||
newenv = xmalloc(sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE)));
|
||||
VALUE newenvval = TypedData_Wrap_Struct(RBASIC_CLASS(envval), RTYPEDDATA_TYPE(envval), 0);
|
||||
rb_env_t *newenv = xmalloc(sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE)));
|
||||
RTYPEDDATA_DATA(newenvval) = newenv;
|
||||
newenv->env_size = local_size + 2;
|
||||
newenv->local_size = local_size;
|
||||
newenv->prev_envval = env->prev_envval;
|
||||
newenv->block = env->block;
|
||||
MEMCPY(newenv->env, env->env, VALUE, prev_local_size + 1);
|
||||
rb_mem_clear(newenv->env + prev_local_size + 1, local_size - prev_local_size);
|
||||
newenvval = TypedData_Wrap_Struct(RBASIC_CLASS(envval), RTYPEDDATA_TYPE(envval), newenv);
|
||||
newenv->env[local_size + 1] = newenvval;
|
||||
envval = newenvval;
|
||||
}
|
||||
|
|
3
vm.c
3
vm.c
|
@ -507,6 +507,7 @@ vm_make_env_each(const rb_thread_t *const th, rb_control_frame_t *const cfp,
|
|||
local_size = cfp->iseq->local_size;
|
||||
}
|
||||
|
||||
envval = TypedData_Wrap_Struct(rb_cEnv, &env_data_type, 0);
|
||||
/* allocate env */
|
||||
env = xmalloc(sizeof(rb_env_t) + ((local_size + 1) * sizeof(VALUE)));
|
||||
env->env_size = local_size + 1 + 1;
|
||||
|
@ -525,7 +526,7 @@ vm_make_env_each(const rb_thread_t *const th, rb_control_frame_t *const cfp,
|
|||
#endif
|
||||
|
||||
/* be careful not to trigger GC after this */
|
||||
envval = TypedData_Wrap_Struct(rb_cEnv, &env_data_type, env);
|
||||
RTYPEDDATA_DATA(envval) = env;
|
||||
|
||||
/*
|
||||
* must happen after TypedData_Wrap_Struct to ensure penvval is markable
|
||||
|
|
Loading…
Add table
Reference in a new issue