Opened 13 months ago

Last modified 13 months ago

#15574 new bug

C wrappers for Haskell foreign exports don't have finalizers (causes memory leak).

Reported by: Valoisa Owned by:
Priority: normal Milestone: 8.6.1
Component: Compiler (FFI) Version: 8.0.1
Keywords: Cc:
Operating System: Windows Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

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.

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.


The main program was built with MSVC 2015.

Attachments (5)

HaskellExports.hs (223 bytes) - added by Valoisa 13 months ago.
HaskellExports.2.hs (223 bytes) - added by Valoisa 13 months ago.
CWrapper.cpp (115 bytes) - added by Valoisa 13 months ago.
main.cpp (157 bytes) - added by Valoisa 13 months ago.
build.sh (121 bytes) - added by Valoisa 13 months ago.

Download all attachments as: .zip

Change History (6)

Changed 13 months ago by Valoisa

Attachment: HaskellExports.hs added

Changed 13 months ago by Valoisa

Attachment: HaskellExports.2.hs added

Changed 13 months ago by Valoisa

Attachment: CWrapper.cpp added

Changed 13 months ago by Valoisa

Attachment: main.cpp added

Changed 13 months ago by Valoisa

Attachment: build.sh added

comment:1 Changed 13 months ago by Valoisa

HaskellExports.2.hs​ is the same as HaskellExports.hs​, it was attached accidentally (no idea how to remove it).

Note: See TracTickets for help on using tickets.