http://d.puremagic.com/issues/show_bug.cgi?id=2590

           Summary: Deallocator is not called if constructor fails.
           Product: D
           Version: 2.023
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzi...@digitalmars.com
        ReportedBy: samu...@voliacable.com


The following test case leaks memory:

import std.c.stdlib;

class C
{
    new(size_t size)
    {
        writefln("In new");
        return malloc(size);
    }

    this()
    {
        writefln("In constructor");
        throw new Exception("Exception in ctor");
    }

    ~this()
    {
        writefln("in destructor");
    }

    delete(void* p)
    {
        writefln("In delete");
        free(p);
    }
}

void main()
{
    try
    {
        auto c = new C;
    }
    catch {}
}
----
In new
In constructor

Deallocator should be called to free the memory.


-- 

Reply via email to