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

add GC guard

new_prev_env is stored in the env_body memory block but this is not
a GC root, so new_prev_env could be freed.
This commit is contained in:
Koichi Sasada 2020-12-03 06:49:52 +09:00
parent 51268be7fe
commit 1f71c7dc81

6
vm.c
View file

@ -1003,6 +1003,7 @@ env_copy(const VALUE *src_ep, VALUE read_only_variables)
VALUE *env_body = ZALLOC_N(VALUE, src_env->env_size); // fill with Qfalse
VALUE *ep = &env_body[src_env->env_size - 2];
volatile VALUE prev_env = Qnil;
if (read_only_variables) {
for (int i=0; i<RARRAY_LENINT(read_only_variables); i++) {
@ -1030,13 +1031,16 @@ env_copy(const VALUE *src_ep, VALUE read_only_variables)
if (!VM_ENV_LOCAL_P(src_ep)) {
const VALUE *prev_ep = VM_ENV_PREV_EP(src_env->ep);
const rb_env_t *new_prev_env = env_copy(prev_ep, read_only_variables);
prev_env = (VALUE)new_prev_env;
ep[VM_ENV_DATA_INDEX_SPECVAL] = VM_GUARDED_PREV_EP(new_prev_env->ep);
}
else {
ep[VM_ENV_DATA_INDEX_SPECVAL] = VM_BLOCK_HANDLER_NONE;
}
return vm_env_new(ep, env_body, src_env->env_size, src_env->iseq);
const rb_env_t *copied_env = vm_env_new(ep, env_body, src_env->env_size, src_env->iseq);
RB_GC_GUARD(prev_env);
return copied_env;
}
static void