www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1551] New: 80kb memory leak with DLLs


           Summary: 80kb memory leak with DLLs
           Product: D
           Version: 1.022
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: minor
          Priority: P4
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: thecybershadow gmail.com

Loading a bare-bones DLL and unloading it leaves a memory leak.

=== DLL source ===
import std.c.windows.windows;
import std.stdio;                       // see bug #1550

extern (C)
        void gc_init();
        void gc_term();
        void _minit();
        void _moduleCtor();
        void _moduleUnitTests();

extern (Windows)
BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
    switch (ulReason)
        case DLL_PROCESS_ATTACH:
            gc_init();                  // initialize GC
            _minit();                   // initialize module list
            _moduleCtor();              // run module constructors
            _moduleUnitTests();         // run module unit tests

        case DLL_PROCESS_DETACH:
            _fcloseallp = null;         // see bug #1550
            gc_term();                  // shut down GC

        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
            // Multiple threads not supported yet
            return false;
    return true;
=== end of DLL source ===

After loading, the process' "private bytes" figure grows by 204-220 KB. After
the DLL is unloaded, only 128-132 KB is freed, leaking about 76 KB of memory
every time.

I have eliminated other factors (a link in the loader) by using a DLL compiled
in another language with the same loader test program.

Oct 07 2007