Resetting the kernel when calling newForeignPtr

Next program:

{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import qualified Data.Vector.Storable as S
import Data.Vector.Storable.Internal
import Foreign.ForeignPtr
import Foreign.Marshal.Alloc

main = do
  let (fp,_,_) = S.unsafeToForeignPtr $ S.fromList [1::Int]
      p = getPtr fp
  copy <- newForeignPtr finalizerFree p -- causes core dump
  print "finished"

      

with kernel dumps with the following error message:

"finished"
*** Error in `./test2': free(): invalid size: 0x00007f4dffc06030 ***
Aborted (core dumped)

      

Did I get it right that this is happening because the two data values ​​are pointing to one bit of memory ( p

specifically) that ghc then tries to garbage collect twice? If so, can I make a copy p

? If this is not the cause, what is causing the problem and how can I fix it? Thanks to

+3
garbage-collection memory-management haskell ghc ffi


source to share


No one has answered this question yet

Check out similar questions:

169
Reading GHC core
110
Reducing the pause time of garbage collection in a Haskell program
48
Mixing Erlang and Haskell
nine
Why doesn't the C # garbage collector try to free memory until the request is satisfied?
3
Python 2: Garbage collection cannot completely free a list of 1 million ints. No problem with 10 million ints
2
Compiled Haskell libraries with FFI imports are invalid when imported into GHCI
2
Criterion causing memory explosion does not see CAF
0
Cheney Garbage Collector: Win32 API Calls
0
allocating / freeing memory for embedded devices
-2
Garbage Collector Android strange behavior



All Articles
Loading...
X
Show
Funny
Dev
Pics