Skip to content

Commit ff124e9

Browse files
jhawthornk0kubun
authored andcommitted
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 38297e4 commit ff124e9

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
@@ -1214,14 +1214,15 @@ tally_up(st_data_t *group, st_data_t *value, st_data_t arg, int existing)
12141214
RB_OBJ_WRITTEN(hash, Qundef, tally);
12151215
}
12161216
*value = (st_data_t)tally;
1217-
if (!SPECIAL_CONST_P(*group)) RB_OBJ_WRITTEN(hash, Qundef, *group);
12181217
return ST_CONTINUE;
12191218
}
12201219

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

0 commit comments

Comments
 (0)