summaryrefslogtreecommitdiff
path: root/ghc/lib/std/PrelIO.lhs
diff options
context:
space:
mode:
authorsimonmar <unknown>2000-07-25 15:20:10 +0000
committersimonmar <unknown>2000-07-25 15:20:10 +0000
commit8d2a22ef9fed6843aa7c77f79984a4e3f69fcfe9 (patch)
tree82458efee051d61274aca9d102770cbafcd98d55 /ghc/lib/std/PrelIO.lhs
parentd6e97b4ebe0e90ecfd6e8d4b8fd1ef594d15b9e0 (diff)
downloadhaskell-8d2a22ef9fed6843aa7c77f79984a4e3f69fcfe9.tar.gz
[project @ 2000-07-25 15:20:10 by simonmar]
Fix bug reported by Hannah Schroeter: reading a file lazily using hGetContents and then closing it using hClose can cause the program to fall over with a deadlock. The reason is that when closing the file in lazyRead{Block,Line,Char}, we set the foreign object in the handle to nullFile__, which causes the finalizer to run (at some point in the future). The finalizer takes the MVar in the handle, frees the contents, but never puts the MVar back. hClose then tries to take the MVar, and deadlocks. The solution is not to set the foreign object to nullFile__ in the first place; I'm not sure why it was done this way, and in fact it leads to a memory leak. hClose itself has a similar problem, leading to a leak of the fileObject.
Diffstat (limited to 'ghc/lib/std/PrelIO.lhs')
-rw-r--r--ghc/lib/std/PrelIO.lhs14
1 files changed, 4 insertions, 10 deletions
diff --git a/ghc/lib/std/PrelIO.lhs b/ghc/lib/std/PrelIO.lhs
index 944ed19639..e93410ffd1 100644
--- a/ghc/lib/std/PrelIO.lhs
+++ b/ghc/lib/std/PrelIO.lhs
@@ -1,5 +1,5 @@
% ------------------------------------------------------------------------------
-% $Id: PrelIO.lhs,v 1.14 2000/07/07 11:03:58 simonmar Exp $
+% $Id: PrelIO.lhs,v 1.15 2000/07/25 15:20:10 simonmar Exp $
%
% (c) The University of Glasgow, 1992-2000
%
@@ -282,9 +282,7 @@ lazyReadBlock handle fo = do
-1 -> -- an error occurred, close the handle
withHandle handle $ \ handle_ -> do
closeFile (haFO__ handle_) 0{-don't bother flushing-} -- ConcHask: SAFE, won't block.
- return (handle_ { haType__ = ClosedHandle,
- haFO__ = nullFile__ },
- "")
+ return (handle_ { haType__ = ClosedHandle }, "")
_ -> do
more <- unsafeInterleaveIO (lazyReadBlock handle fo)
stToIO (unpackNBytesAccST buf bytes more)
@@ -298,9 +296,7 @@ lazyReadLine handle fo = do
-1 -> -- an error occurred, close the handle
withHandle handle $ \ handle_ -> do
closeFile (haFO__ handle_) 0{- don't bother flushing-} -- ConcHask: SAFE, won't block
- return (handle_ { haType__ = ClosedHandle,
- haFO__ = nullFile__ },
- "")
+ return (handle_ { haType__ = ClosedHandle }, "")
_ -> do
more <- unsafeInterleaveIO (lazyReadLine handle fo)
buf <- getBufStart fo bytes -- ConcHask: won't block
@@ -318,9 +314,7 @@ lazyReadChar handle fo = do
-1 -> -- error, silently close handle.
withHandle handle $ \ handle_ -> do
closeFile (haFO__ handle_) 0{-don't bother flusing-} -- ConcHask: SAFE, won't block
- return (handle_{ haType__ = ClosedHandle,
- haFO__ = nullFile__ },
- "")
+ return (handle_{ haType__ = ClosedHandle }, "")
_ -> do
more <- unsafeInterleaveIO (lazyReadChar handle fo)
return (chr char : more)