[project @ 2000-07-25 15:20:10 by simonmar]
authorsimonmar <unknown>
Tue, 25 Jul 2000 15:20:10 +0000 (15:20 +0000)
committersimonmar <unknown>
Tue, 25 Jul 2000 15:20:10 +0000 (15:20 +0000)
commit8d2a22ef9fed6843aa7c77f79984a4e3f69fcfe9
tree82458efee051d61274aca9d102770cbafcd98d55
parentd6e97b4ebe0e90ecfd6e8d4b8fd1ef594d15b9e0
[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.
ghc/lib/std/PrelHandle.lhs
ghc/lib/std/PrelIO.lhs