Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #5

Open
shlok opened this issue Nov 10, 2019 · 0 comments
Open

Memory leak #5

shlok opened this issue Nov 10, 2019 · 0 comments

Comments

@shlok
Copy link

shlok commented Nov 10, 2019

It seems this library (random-bytestring-0.1.3.2) leaks memory. One can run the program

module Main where
import Data.ByteString.Random.MWC (random)
main :: IO ()
main = random 10000 >> main

and watch memory blowing up.

Here are two ideas for fixes to Data.ByteString.Random.Internal:

1. Replace bracketOnError with bracket and copy the ByteString at the end:

bracket (mallocBytes len8) free $ \ptr@(Ptr !addr)  do
    {-# SCC "go" #-} go ptr
    {-# SCC "pack" #-} unsafePackAddressLen len8 addr >>= return . copy

2. Somehow replace unsafePackAddressLen with unsafePackMallocCStringLen. This sounds better (no copying), but I didn’t manage to get the types to match.

Update. For 2, here is a suggestion:

bracketOnError (mallocBytes len8) free $ \ptr@(Ptr !addr)  do
    {-# SCC "go" #-} go ptr
    {-# SCC "pack" #-} unsafePackMallocCStringLen (castPtr ptr :: Ptr CChar, len8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant