I have a C function that creates a string with a terminating zero and returns a pointer to it, there is also a corresponding release function.
foreign import ccall unsafe "get_str" getStr :: IO CString foreign import ccall unsafe "free_str" freeStr :: CString -> IO ()
I want to create a Haskell string from the returned CString and release the CString as soon as possible.
do cStr <- getStr str <- peekCString cStr freeStr cStr
Is it safe to free cStr before using str? In other words, does peekCString create a Haskell String right away or is it lazy to create?
source share