From fc8ee1dc84c1486cea3a93601992b4031121fcc9 Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 20 Apr 2004 09:18:46 +0000 Subject: [PATCH] [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. --- GHC/Handle.hs | 3 +++ 1 file changed, 3 insertions(+) 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). -- 1.7.10.4