Skip to content

Commit a0fe009

Browse files
authored
Don't enumerate io->blocking_operations if fork generation is different. (ruby#13359)
1 parent 35000ac commit a0fe009

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

io.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5692,8 +5692,13 @@ rb_io_memsize(const rb_io_t *io)
56925692
if (io->writeconv) size += rb_econv_memsize(io->writeconv);
56935693

56945694
struct rb_io_blocking_operation *blocking_operation = 0;
5695-
ccan_list_for_each(&io->blocking_operations, blocking_operation, list) {
5696-
size += sizeof(struct rb_io_blocking_operation);
5695+
5696+
// Validate the fork generation of the IO object. If the IO object fork generation is different, the list of blocking operations is not valid memory. See `rb_io_blocking_operations` for the exact semantics.
5697+
rb_serial_t fork_generation = GET_VM()->fork_gen;
5698+
if (io->fork_generation == fork_generation) {
5699+
ccan_list_for_each(&io->blocking_operations, blocking_operation, list) {
5700+
size += sizeof(struct rb_io_blocking_operation);
5701+
}
56975702
}
56985703

56995704
return size;

0 commit comments

Comments
 (0)