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.
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, usenewForeignPtr_
instead.