Fix crash on shutdown in the Darwin backend

This was 100% reproducible when closing the backend while still injected
into two or more processes.
Fix crash on shutdown in the Linux backend

This was 100% reproducible when closing the backend while still injected
into two or more processes.