[GHC] #10415: ForeignPtr touched in FFI wrapper is never discarded

GHC ghc-devs at haskell.org
Thu May 14 09:15:15 UTC 2015


#10415: ForeignPtr touched in FFI wrapper is never discarded
-------------------------------------+-------------------------------------
        Reporter:  Deewiant          |                   Owner:
            Type:  bug               |                  Status:  closed
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.10.1
      Resolution:  invalid           |                Keywords:
Operating System:  Linux             |            Architecture:  x86_64
 Type of failure:  Runtime           |  (amd64)
  performance bug                    |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:
-------------------------------------+-------------------------------------

Comment (by Deewiant):

 No, you're absolutely right. I suspected that the compiler couldn't
 reasonably do anything here due to the danger of the wrapper being
 "squirreled away" as you say. :-) What I thought might be possible is some
 sort of proof based on things like:

 1. In the example, the wrapper is immediately discarded, so there's no
 need for it to live at all, really.
 2. Perhaps a "safe" foreign call is only made immediately next to the
 wrapper allocation and the wrapper is not referenced elsewhere, so the
 compiler could see where its lifetime ends.

 But I didn't realize that the wrappers are functions that require manual
 freeing! `freeHaskellFunPtr` is something I was missing entirely. I was
 looking in the FFI sections of the Haskell 2010 report to see if there was
 anything like that for freeing wrapper functions, but apparently I
 should've looked elsewhere too.

 Thanks, and sorry for the noise.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10415#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list