Could you expand on this fragment of code?  Perhaps a fullying
compilable example?  It depends how you are getting the pointer, not
how you are reading data out of the pointer.  For example, if you use
"withCString" to get ptr then the memory will be freed automatically.

Thomas

On Sun, Nov 29, 2009 at 9:00 AM, El Barto <[email protected]> wrote:
> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to