[GHC] #15574: C wrappers for Haskell foreign exports don't have finalizers (causes memory leak).

GHC ghc-devs at haskell.org
Tue Aug 28 15:25:46 UTC 2018


#15574: C wrappers for Haskell foreign exports don't have finalizers (causes memory
leak).
-------------------------------------+-------------------------------------
           Reporter:  Valoisa        |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:  8.6.1
          Component:  Compiler       |           Version:  8.0.1
  (FFI)                              |
           Keywords:                 |  Operating System:  Windows
       Architecture:                 |   Type of failure:  Runtime
  Unknown/Multiple                   |  performance bug
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 For each foreign export RTS creates a static C wrapper, which is
 initialized on {{{DLL_PROCESS_ATTACH}}}, but it has no
 finalizer/destructor to be called during {{{DLL_PROCESS_DETACH}}}. So it
 will stay alive till the program termination. That's why if one uses a
 Haskell DLL in their C/C++ project, **consumed memory is not fully
 released after freeing the library**.
 [[br]][[br]]
 There are four files attached to this ticket.
 * **HaskellExports.hs** contains exact one foreign export function;
 * **CWrapper.cpp** is supposed to contain wrappers to the Haskell
 functions, described in ''HaskellExports.hs'', but it doesn't because they
 make no difference;
 * **main.cpp**: here in an endless loop the DLL (built with the help of
 the script below) is loaded and freed at once. Launched program is crashed
 in a while (because it runs out of memory);
 * **build.sh** is a script for building the library.
 [[br]]
 The main program was built with MSVC 2015.

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


More information about the ghc-tickets mailing list