
#14346: 8.2.1 regression: heap corruption after safe foreign calls -------------------------------------+------------------------------------- Reporter: andrewchen | Owner: (none) Type: bug | Status: infoneeded Priority: highest | Milestone: Component: Runtime System | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonmar): Interesting, can someone boil down the transformation that dropped the `touch#`? Simon: `touch#` is keeping the `ByteArray#` alive until after the `action`, in `allocaBytes` (see comment:18). The action itself doesn't keep the array alive, because it is working with the raw pointer, not the `ByteArray#`. This is how we allocate temporary memory for marshalling data between Haskell and C, because it's a lot faster to allocate memory on the Haskell heap than to use `malloc()` and `free()`. I imagine the simplifier has proven that `action` never returns and then dropped the `case` with the continuation containing the `touch#`. That seems like a reasonable thing to do. I like @bgamari's alternative suggestion of `with#`, although we probably want it to be {{{ with# :: a -> (State# s -> (# State# s, b #)) -> State# s -> (# State# s, b #) }}} otherwise the second argument must be a thunk (yuck). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14346#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler