Skip to content
  • Simon Marlow's avatar
    8d2a22ef
    [project @ 2000-07-25 15:20:10 by simonmar] · 8d2a22ef
    Simon Marlow authored
    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.
    8d2a22ef
    [project @ 2000-07-25 15:20:10 by simonmar]
    Simon Marlow authored
    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.
Loading