in hClose, free the handle buffer by replacing it with an empty one
[ghc-base.git] / GHC / Handle.hs
index 261c81c..263b86d 100644 (file)
@@ -1158,6 +1158,7 @@ hClose_handle_ handle_ = do
 
     -- free the spare buffers
     writeIORef (haBuffers handle_) BufferListNil
+    writeIORef (haBuffer  handle_) noBuffer
   
 #ifndef mingw32_HOST_OS
     -- unlock it
@@ -1170,6 +1171,9 @@ hClose_handle_ handle_ = do
                     haType      = ClosedHandle
                   })
 
+{-# NOINLINE noBuffer #-}
+noBuffer = unsafePerformIO $ allocateBuffer 1 ReadBuffer
+
 -----------------------------------------------------------------------------
 -- Detecting and changing the size of a file