From f6dae3813effa7cf1855b793a87a2b0efddf2f7e Mon Sep 17 00:00:00 2001 From: Luite Stegeman <stegeman@gmail.com> Date: Mon, 14 Oct 2013 20:59:35 +0200 Subject: [PATCH] make rawSystemIOWithEnv close its handles --- Cabal/Distribution/Simple/Utils.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Cabal/Distribution/Simple/Utils.hs b/Cabal/Distribution/Simple/Utils.hs index faa3177ac1..ae951deba9 100644 --- a/Cabal/Distribution/Simple/Utils.hs +++ b/Cabal/Distribution/Simple/Utils.hs @@ -175,7 +175,7 @@ import System.Directory import System.IO ( Handle, openFile, openBinaryFile, openBinaryTempFile , IOMode(ReadMode), hSetBinaryMode - , hGetContents, stderr, stdout, hPutStr, hFlush, hClose ) + , hGetContents, stdin, stderr, stdout, hPutStr, hFlush, hClose ) import System.IO.Error as IO.Error ( isDoesNotExistError, isAlreadyExistsError , ioeSetFileName, ioeGetFileName, ioeGetErrorString ) @@ -473,9 +473,15 @@ rawSystemIOWithEnv verbosity path args mcwd menv inp out err = do , Process.std_err = mbToStd err } unless (exitcode == ExitSuccess) $ do debug verbosity $ path ++ " returned " ++ show exitcode + mapM_ maybeClose [inp, out, err] return exitcode where -- Also taken from System.Process + maybeClose :: Maybe Handle -> IO () + maybeClose (Just hdl) + | hdl /= stdin && hdl /= stdout && hdl /= stderr = hClose hdl + maybeClose _ = return () + mbToStd :: Maybe Handle -> StdStream mbToStd Nothing = Inherit mbToStd (Just hdl) = UseHandle hdl -- GitLab