Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default out-marshaller for ForeignPtr adds finalizer for null ptr #234

Open
mpdairy opened this issue Apr 20, 2019 · 1 comment
Open

default out-marshaller for ForeignPtr adds finalizer for null ptr #234

mpdairy opened this issue Apr 20, 2019 · 1 comment

Comments

@mpdairy
Copy link

mpdairy commented Apr 20, 2019

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.

@jimenezrick
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants