Skip to content

Commit 8351378

Browse files
rb_fiber_scheduler_blocking_operation_wait can garbage collect blocking_operation incorrectly. (ruby#16908)
Place RB_GC_GUARD(blocking_operation) after the last implicit use of the VALUE — all accesses via the derived `operation` pointer — so the compiler cannot treat blocking_operation as dead before this point, keeping it reachable as a GC root through rb_funcall and through all subsequent uses of the raw pointer.
1 parent 276f0d9 commit 8351378

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

scheduler.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,9 @@ VALUE rb_fiber_scheduler_blocking_operation_wait(VALUE scheduler, void* (*functi
11111111
operation->data2 = NULL;
11121112
operation->unblock_function = NULL;
11131113

1114+
// Ensure that the blocking operation remains visible until this point:
1115+
RB_GC_GUARD(blocking_operation);
1116+
11141117
// If the blocking operation was never executed, return Qundef to signal the caller to use rb_nogvl instead
11151118
if (current_status == RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED) {
11161119
return Qundef;

0 commit comments

Comments
 (0)