c2hs
c2hs copied to clipboard
default out-marshaller for ForeignPtr adds finalizer for null ptr
Sometimes C functions return null pointers. The default marshaller for ForeignPtr's in c2hs still adds a finalizer for null pointers, which causes the application to crash when the memory is freed. I suggest the default marshaller should check if the ptr equals nullPtr
and, if so, use newForeignPtr_
instead.
I was also looking into this. In my case, I ended up writing a thin C wrapper function used as finalizer, where I checked if the pointer is not NULL and then I call the function doing the release operation.