
#15595: Stack overflow in withArgs leads to infinite memory-consuming loop ----------------------------------+-------------------------------------- Reporter: NeilMitchell | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.5 Resolution: | Keywords: Operating System: Windows | Architecture: x86_64 (amd64) Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+-------------------------------------- Comment (by osa1): The reason why the original code loops while my first example doesn't is because I don't use `getArgs`. `getArgs` calls this function: {{{#!haskell withProgArgv :: [String] -> IO a -> IO a withProgArgv new_args act = do pName <- System.Environment.getProgName existing_args <- System.Environment.getArgs bracket_ (setProgArgv new_args) (setProgArgv (pName:existing_args)) act }}} The `setProgArgv new_args` part is where we get a stack overflow, but it's evaluated in masked state because of `bracket_`: {{{#!haskell bracket_ before after thing = bracket before (const after) (const thing) bracket before after thing = mask $ \restore -> do a <- before r <- restore (thing a) `onException` after a _ <- after a return r }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15595#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler