Fix hClose002 with the threaded RTS IO manager

If 'close fd' failed, then the MVars in the callbackTables would be
left empty, which caused deadlocks when we tried to 'take' them again.

Now we use 'finally' to ensure that they are refilled even if 'close'
throws an exception.
Fix hSetBuffering004 to work with dynamic ghci

We need to actually consume the rest of stdin, or ghci will try
to interpret it as commands.