From: simonmar Date: Tue, 20 Apr 2004 09:18:46 +0000 (+0000) Subject: [project @ 2004-04-20 09:18:46 by simonmar] X-Git-Tag: nhc98-1-18-release~328 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=fc8ee1dc84c1486cea3a93601992b4031121fcc9;p=ghc-base.git [project @ 2004-04-20 09:18:46 by simonmar] Fix a file descriptor leak in openFile: if openFd fails, then we weren't closing the newly created descriptor. --- diff --git a/GHC/Handle.hs b/GHC/Handle.hs index 8f0e50d..6370476 100644 --- a/GHC/Handle.hs +++ b/GHC/Handle.hs @@ -714,6 +714,9 @@ openFile' filepath mode binary = (c_open f (fromIntegral oflags) 0o666) openFd fd Nothing filepath mode binary truncate + `catchException` \e -> do c_close (fromIntegral fd); throw e + -- NB. don't forget to close the FD if openFd fails, otherwise + -- this FD leaks. -- ASSERT: if we just created the file, then openFd won't fail -- (so we don't need to worry about removing the newly created file -- in the event of an error).