[project @ 2004-04-20 09:18:46 by simonmar]
authorsimonmar <unknown>
Tue, 20 Apr 2004 09:18:46 +0000 (09:18 +0000)
committersimonmar <unknown>
Tue, 20 Apr 2004 09:18:46 +0000 (09:18 +0000)
Fix a file descriptor leak in openFile: if openFd fails, then we
weren't closing the newly created descriptor.

GHC/Handle.hs

index 8f0e50d..6370476 100644 (file)
@@ -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).