Bug 2491 – druntime GC wrongly frees data pointed to by TLS.
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-12-05T10:08:00Z
Last change time
2015-06-09T01:20:44Z
Assigned to
bugzilla
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2008-12-05T10:08:58Z
Apparently, under certain circumstances, the D 2.21 druntime GC wrongly frees memory locations pointed to by thread-local storage.
import core.memory, std.stdio;
__thread Stuff* stuff1;
struct Stuff {
uint num;
}
void main() {
stuff1 = new Stuff;
stuff1.num = 1;
auto bar = new byte[1024 * 1024];
auto stuff2 = new Stuff;
stuff2.num = 2;
writeln(stuff1, "\t", stuff2); // Same address.
writeln(stuff1.num, "\t", stuff2.num); // Both 2.
}
If you disable the GC using GC.disable at the top of main() or change stuff1 to a non-thread-local, the problem goes away.