Bug 3237 – Access Violation during reference counting

Status
RESOLVED
Resolution
INVALID
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-08-08T12:30:00Z
Last change time
2015-06-09T01:26:48Z
Assigned to
nobody
Creator
bartosz

Attachments

IDFilenameSummaryContent-TypeSize
439bug.dtest case for access violatin while reference countingapplication/octet-stream1366
440bug.dsimplified case with a write in the destructor of Counterapplication/octet-stream1492

Comments

Comment #0 by bartosz — 2009-08-08T12:30:53Z
RcName is a struct that does reference counting. When I store an instance of RcName in an object, everything seems to go fine, except that I get an access violation during the final destruction.
Comment #1 by bartosz — 2009-08-08T12:31:46Z
Created attachment 439 test case for access violatin while reference counting
Comment #2 by bugzilla — 2009-08-08T13:23:38Z
compile with -gc and run under windbg, the windows debugger. Shows that it crashes because _cnt is null in the first line of release().
Comment #3 by bartosz — 2009-08-08T15:18:14Z
Created attachment 440 simplified case with a write in the destructor of Counter
Comment #4 by bartosz — 2009-08-08T15:20:08Z
I simplified the example. It turns out that the destructor of a class object Counter is called. I have no idea what mechanism may call the destructor other than GC. A new file attached.
Comment #5 by bugzilla — 2009-08-14T22:49:38Z
The cause of the crash is there is a dependency in the code on the order in which the gc runs the destructors on collected objects. Dependency on this order is not valid D code. Generally, one cannot refer to other objects on the GC heap when inside a destructor for a GC object.