[project @ 2000-04-14 12:49:39 by simonmar]
authorsimonmar <unknown>
Fri, 14 Apr 2000 12:49:39 +0000 (12:49 +0000)
committersimonmar <unknown>
Fri, 14 Apr 2000 12:49:39 +0000 (12:49 +0000)
Free the spare buffers immediately we hClose a file handle.

ghc/lib/std/PrelHandle.lhs

index 8d02b32..1731cbf 100644 (file)
@@ -392,11 +392,16 @@ hClose handle =
              is finalized. (we overwrite the file ptr in the underlying
             FileObject with a NULL as part of closeFile())
          -}
-          if rc == (0::Int)
-          then return (handle_{ haType__   = ClosedHandle,
-                                haFO__     = nullFile__ })
-           else constructErrorAndFail "hClose"
 
+          if (rc /= 0)
+           then constructErrorAndFail "hClose"
+
+                 -- free the spare buffers (except the handle buffer)
+                 -- associated with this handle.
+          else do freeBuffers (haBuffers__ handle_)
+                  return (handle_{ haType__    = ClosedHandle,
+                                   haFO__      = nullFile__,
+                                   haBuffers__ = [] })
 \end{code}
 
 Computation $hClose hdl$ makes handle {\em hdl} closed.  Before the