From 5a21d20b0f25de3d829de90d219cb66855f91d58 Mon Sep 17 00:00:00 2001
From: simonmar <unknown>
Date: Fri, 14 Apr 2000 12:49:39 +0000
Subject: [PATCH] [project @ 2000-04-14 12:49:39 by simonmar] Free the spare
 buffers immediately we hClose a file handle.

---
 ghc/lib/std/PrelHandle.lhs | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/ghc/lib/std/PrelHandle.lhs b/ghc/lib/std/PrelHandle.lhs
index 8d02b32869a7..1731cbf4ce8e 100644
--- a/ghc/lib/std/PrelHandle.lhs
+++ b/ghc/lib/std/PrelHandle.lhs
@@ -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
-- 
GitLab