Thomas, I made the change below to stop a SEGV on thread exit as evinced by the threadidafterfork test in the testsuite.
The problem is that this code overwrites impure_ptr with the contents of the thread which called fork, which is not the correct thing to do since _impure_ptr contains global information not present in the calling threads reent structure.
I hope it makes sense. If there is some better way to do this, please feel free to check it in. This looked right to me, though.
It is ok for me.
I was not sure whether the thread local reent contains something important that should be restored after a fork, but with the _GLOBAL_REENT patches to newlib it is better to keep _impure_ptr unchanged.
Thomas