8000 Fix too early writebarrier in tally_up · ruby/ruby@a7dc515 · GitHub
[go: up one dir, main page]

Skip to content

Commit a7dc515

Browse files
committed
Fix too early writebarrier in tally_up
After returning from the callback in st_update is the point that the hash table may be resized, which could trigger a GC and mark the table being used for the tally. RUBY_GC_LIBRARY=wbcheck WBCHECK_VERIFY_AFTER_WB=1 ./miniruby -e '(0...100).map(&:to_s).tally'
1 parent e3ec101 commit a7dc515

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

enum.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,14 +1215,15 @@ tally_up(st_data_t *group, st_data_t *value, st_data_t arg, int existing)
12151215
RB_OBJ_WRITTEN(hash, Qundef, tally);
12161216
}
12171217
*value = (st_data_t)tally;
1218-
if (!SPECIAL_CONST_P(*group)) RB_OBJ_WRITTEN(hash, Qundef, *group);
12191218
return ST_CONTINUE;
12201219
}
12211220

12221221
static VALUE
12231222
rb_enum_tally_up(VALUE hash, VALUE group)
12241223
{
1225-
rb_hash_stlike_update(hash, group, tally_up, (st_data_t)hash);
1224+
if (!rb_hash_stlike_update(hash, group, tally_up, (st_data_t)hash)) {
1225+
RB_OBJ_WRITTEN(hash, Qundef, group);
1226+
}
12261227
return hash;
12271228
}
12281229

0 commit comments

Comments
 (0)
0