diff options
author | Ian Lynagh <ian@well-typed.com> | 2012-12-01 22:31:48 +0000 |
---|---|---|
committer | Ian Lynagh <ian@well-typed.com> | 2012-12-01 22:34:02 +0000 |
commit | 76dad7afeaef33576940b64a7b3be91d05434df5 (patch) | |
tree | 0708373e67fe1613ec84bdcbe96e2cae749ed0b4 /System | |
parent | e12ccd7203ac3f0133365a9d3d802195e534fd8e (diff) |
Fix putenv; trac #7342
We were freeing the string, but the string becomes part of the
environment.
Diffstat (limited to 'System')
-rw-r--r-- | System/Posix/Env.hsc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc index ecc6281..f7878b8 100644 --- a/System/Posix/Env.hsc +++ b/System/Posix/Env.hsc @@ -38,7 +38,7 @@ import Foreign.Ptr import Foreign.Storable import Control.Monad import Data.Maybe (fromMaybe) -import System.Posix.Internals (withFilePath, peekFilePath) +import System.Posix.Internals -- |'getEnv' looks up a variable in the environment. @@ -124,8 +124,11 @@ unsetEnv name = putEnv (name ++ "=") -- and is equivalent to @setEnv(key,value,True{-overwrite-})@. putEnv :: String -> IO () -putEnv keyvalue = withFilePath keyvalue $ \s -> - throwErrnoIfMinus1_ "putenv" (c_putenv s) +putEnv keyvalue = do s <- newFilePath keyvalue + -- Do not free `s` after calling putenv. + -- According to SUSv2, the string passed to putenv + -- becomes part of the enviroment. #7342 + throwErrnoIfMinus1_ "putenv" (c_putenv s) foreign import ccall unsafe "putenv" c_putenv :: CString -> IO CInt |