[GHC] #3486: Data.ByteString.elemIndices causes SEGV
GHC
trac at galois.com
Sat Sep 12 15:33:17 EDT 2009
#3486: Data.ByteString.elemIndices causes SEGV
-------------------------------+--------------------------------------------
Reporter: nwn | Owner: duncan
Type: bug | Status: new
Priority: high | Milestone: 6.12.1
Component: libraries/base | Version: 6.10.4
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Os: MacOS X
Architecture: x86 |
-------------------------------+--------------------------------------------
Changes (by igloo):
* priority: normal => high
* owner: igloo => duncan
Comment:
The problem is in `elemIndices`:
{{{
elemIndices :: Word8 -> ByteString -> [Int]
elemIndices w (PS x s l) = inlinePerformIO $ withForeignPtr x $ \p -> do
let ptr = p `plusPtr` s
STRICT1(loop)
loop n = let q = inlinePerformIO $ memchr (ptr `plusPtr` n)
w (fromIntegral (l - n))
in if q == nullPtr
then []
else let i = q `minusPtr` ptr
in i : loop (i+1)
return $! loop 0
}}}
The lazy thunk using `p` escapes from the `withForeignPtr`, so `x` can be
freed.
Replacing `[]` with:
{{{
inlinePerformIO $ do touchForeignPtr x
return []
}}}
makes the segfault go away.
I'm assigning this to duncan so that he or Don can fix it in the upstream
repo, and also check if any other functions have the same problem.
I assume that this will also fix #3487.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3486#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list