c2hs icon indicating copy to clipboard operation
c2hs copied to clipboard

default out-marshaller for ForeignPtr adds finalizer for null ptr

Open mpdairy opened this issue 5 years ago • 1 comments

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.

mpdairy avatar Apr 20 '19 03:04 mpdairy

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.

jimenezrick avatar May 07 '20 19:05 jimenezrick