Fix potential leaks when forking with multiple threads Some of this work was done in #883 But there are still potential leaks around both TLS and heap allocated objects. See FIXMEs in comments for more details about what needs investigating and fixing.