[Issue 9352] New: Memory corruption in delegate called by struct dtor
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jan 18 12:07:20 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9352
Summary: Memory corruption in delegate called by struct dtor
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: major
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: hsteoh at quickfur.ath.cx
--- Comment #0 from hsteoh at quickfur.ath.cx 2013-01-18 12:07:19 PST ---
Code:
------------SNIP-----------
import std.stdio;
static ubyte canary[32] = [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
];
struct S {
ubyte[32] t;
void delegate()[] destructor;
this(int dummy) {
t[] = canary[];
writefln("ctor: %s", t);
destructor ~= {
writefln("deleg: %s", t);
};
}
~this() {
writefln("dtor: %s", t);
// we're just undoing everything the constructor did, in
// reverse order, same criteria
foreach_reverse(d; destructor)
d();
}
}
auto abc(int dummy) {
return S(0);
}
void main() {
auto input = abc(0);
writefln("main: %s", input.t);
}
------------SNIP-----------
Output:
------------SNIP-----------
ctor: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
main: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
dtor: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
deleg: [0, 0, 0, 0, 0, 0, 0, 0, 24, 25, 26, 27, 28, 29, 30, 31, 240, 239, 168,
189, 184, 127, 0, 0, 152, 34, 64, 0, 0, 0, 0, 0]
------------SNIP-----------
This code was minimized from Adam Ruppe's terminal.d. The function abc(int
dummy) is necessary; if S is constructed in main, the problem does not occur.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list