Commit 2b3aa30
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 5a73339 commit 2b3aa30
1 file changed
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4816 | 4816 | | |
4817 | 4817 | | |
4818 | 4818 | | |
4819 | | - | |
| 4819 | + | |
| 4820 | + | |
| 4821 | + | |
| 4822 | + | |
| 4823 | + | |
4820 | 4824 | | |
4821 | 4825 | | |
4822 | 4826 | | |
| |||
0 commit comments