#4221: Calling freeHaskellFunctionPtr from C finalizer leads to crashes
---------------------------------+------------------------------------------
Reporter: ravi_n | Owner:
Type: bug | Status: new
Priority: normal | Component: Runtime System
Version: 6.12.3 | Keywords:
Os: Unknown/Multiple | Testcase:
Architecture: Unknown/Multiple | Failure: Runtime crash
---------------------------------+------------------------------------------
I recently discovered that calling freeHaskellFunctionPtr from a C
finalizer (as seems natural to do if the object you're cleaning up on the
C side is holding on to a Haskell function wrapper) leads to strange
crashes.
The attached program (which is a stress-test loop of allocating function
wrappers, using them and then freeing them) illustrates the problem.
You can compile it with:
ghc --make !WrapperTest2.hs !HsFunction.c -o !WrapperTest2 -main-is
!WrapperTest2
Depending on the platform and compilation flags I've noticed different
results. Compiled as above (on Windows) I get: !WrapperTest2.exe: internal
error: stg_ap_p_ret
Compiled with -debug I get: !WrapperTest2.exe: internal error: ASSERTION
FAILED: file rts\Stable.c, line 224
On Windows, these results do not change if I compile with -threaded.
On Linux, without -threaded, I get the same results as Windows.
However, with -threaded I get different behavior.
With -threaded and without -debug the program eventually deadlocks.
With -threaded and -debug I get the following message: !WrapperTest2:
internal error: multiple ACQUIRE_LOCK: rts/Stable.c 284
I'm currently working around the issue by using Haskell finalizers (which
don't seem to have this problem), but I thought I should report the bug.
I'd also appreciate feedback on whether using Haskell finalizers is
actually a safe workaround for this issue or if I've just been lucky so
far.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4221>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs