If exiting due to an error in a multithreaded section of the code, there may be other threads still running, accessing the memory mapped area. Just remove the temporary file (on unix, just remove it, while it has got a remove-on-exit flag set on windows) and close its file descriptor, while keeping the memory mapping intact.
This implements @pcc's suggestion on fixing PR38647.
I'm a little weary about the fact that the existing comment in FileOutputBuffer.cpp says "Close the mapping before deleting the temp file, so that the removal succeeds.", while this approach taken by this patch seems to work fine (at least on windows 10). OTOH we don't actually delete the file on windows, we just close the FD.