summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2021-10-06 15:38:33 -0400
committerGitHub <noreply@github.com>2021-10-06 15:38:33 -0400
commit76228191474c76810043b294a74bbb2f1808b3d9 (patch)
tree4efb8ad85ffd1750b3cd589eec96872f600d4ef7 /vm.c
parentd53493715cd1a1463b98291e0ad92e2723236698 (diff)
Fix Ractor.make_shareable changing locals for Procs
env_copy() uses rb_ary_delete_at() with a loop counting up while iterating through the list of read only locals. rb_ary_delete_at() can shift elements in the array to an index lesser than the loop index, causing locals to be missed and set to Qfalse in the returned environment. Iterate through the locals in reverse instead, this way the shifting never happens for locals that are yet to be visited and we process all the locals in the array. [Bug #18023]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4940 Merged-By: XrXr
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/vm.c b/vm.c
index 5a1756e33a..d5e984ce61 100644
--- a/vm.c
+++ b/vm.c
@@ -1006,7 +1006,7 @@ env_copy(const VALUE *src_ep, VALUE read_only_variables)
volatile VALUE prev_env = Qnil;
if (read_only_variables) {
- for (int i=0; i<RARRAY_LENINT(read_only_variables); i++) {
+ for (int i=RARRAY_LENINT(read_only_variables)-1; i>=0; i--) {
ID id = SYM2ID(rb_str_intern(RARRAY_AREF(read_only_variables, i)));
for (unsigned int j=0; j<src_env->iseq->body->local_table_size; j++) {