Skip to content

Commit 7978b22

Browse files
committed
Fix GCC optimization bug eliminating rb_gc_before_fork()
Previously (with -O3), `rb_gc_before_fork` did nothing (it just returned). Now, it executes an atomic instruction to force memory consistency before the operating system forks the process. This prevents stale heap objects from persisting across fork, which can lead to double frees in the child process. Old Version: ``` 0000000000071410 <rb_gc_before_fork>: 71410: c3 ret <-- Return immediately ... ``` New Version: ``` 0000000000071490 <rb_gc_before_fork>: 71490: f0 48 83 0c 24 00 lock orq $0x0,(%rsp) 71496: c3 ret ... ```
1 parent 130c37d commit 7978b22

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5618,6 +5618,7 @@ void
56185618
rb_gc_before_fork(void)
56195619
{
56205620
rb_gc_impl_before_fork(rb_gc_get_objspace());
5621+
__atomic_thread_fence(RBIMPL_ATOMIC_SEQ_CST);
56215622
}
56225623

56235624
void

0 commit comments

Comments
 (0)