[Issue 19386] New: Destructor not called when constructed inside if condition, leading to memory leak
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Nov 10 00:35:22 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19386
Issue ID: 19386
Summary: Destructor not called when constructed inside if
condition, leading to memory leak
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: jesse.bruce at economicmodeling.com
Destructor is not called when an object is constructed inside of an if
statement and opCast!bool returns false.
Reproduction:
struct Thing
{
this(int* i) { ptr = i; (*ptr)++; }
~this() { (*ptr)--; }
T opCast(T:bool)() { return false; }
int* ptr;
}
Thing makeThing(int* p)
{
return Thing(p);
}
void main()
{
int i;
{
if(auto t = makeThing(&i))
{
import std.stdio;
writeln("hello?");
}
}
assert(i == 0);
}
Observed output:
core.exception.AssertError at regextest.d(24): Assertion failure
Expected output:
--
More information about the Digitalmars-d-bugs
mailing list