[Haskell-cafe] peekCString & free memory

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun Nov 29 12:55:52 EST 2009

Hello El,

Sunday, November 29, 2009, 8:00:02 PM, you wrote:

segfault is due to free, you may omit peekCString call.
you should free only memory that was malloced and not freed other way

> Hello,
> I get a segfault when I do
> str <- peekCString ptr
> free ptr
> return (Just str)

> But not when I don't free the C pointer.
> I also get the same behaviour with ByteString.packCString...

>  Could you please tell me if the memory is correctly freed by GHC  when I don't do it myself?
> And how can I specify a custom free function (i.e. xmlFree function in libxml2)?
> Maybe I should use a data type with two fields : the
> String/ByteString and the ForeignPtr to the CString?
> Regards

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com

More information about the Haskell-Cafe mailing list