Bug 15044 – [REG2.068.0] destroy might leak memory

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-11T21:53:00Z
Last change time
2015-09-24T08:15:59Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-09-11T21:53:18Z
cat > bug.d << CODE struct Vector { ~this() { } RefCounted!Vector dup() { return RefCounted!Vector(&this); } } struct RefCounted(T) { ~this() { .destroy(*t); // __xdtor of Vector not yet available static assert(__traits(hasMember, T, "__xdtor")); } T* t; } CODE dmd -c bug ---- bug.d(18): Error: static assert (__traits(hasMember, Vector, "__xdtor")) is false bug.d(7): instantiated from here: RefCounted!(Vector) ---- The problem is that __xdtor is not yet available when the destructor of RefCounted is analyzed, hence .destroy won't call the destructor of Vector. It seems that the creation of __xdtor should happen earlier.
Comment #1 by code — 2015-09-12T00:07:01Z
This breaks b/c of the following semantic analysis issue. Vector.semantic dup.semantic RefCounted!Vector.semantic (return type) RefCounted!Vector buildOpAssign RefCounted!Vector.dtor.semantic3 (buildOpAssign) It seems that buildOpAssign is too greedy running semantic3 during a semantic1 pass of a struct.
Comment #2 by code — 2015-09-12T01:26:52Z
Any idea how to solve this @Kenji? We could try to do semantic3 for buildOpAssign later, but then we'd have to add a special case to op_overload and gag assign usage or so.
Comment #3 by k.hara.pg — 2015-09-14T10:44:06Z
(In reply to Martin Nowak from comment #2) > Any idea how to solve this @Kenji? > We could try to do semantic3 for buildOpAssign later, but then we'd have to > add a special case to op_overload and gag assign usage or so. I think currently there's no way than treat the generated opAssign function specially. I'll post a PR soon.
Comment #4 by k.hara.pg — 2015-09-14T16:49:55Z
Comment #5 by github-bugzilla — 2015-09-14T17:44:00Z
Commits pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/8e4676303a688ce3a034b38508b5e5b8c7bfa7e0 fix Issue 15044 - destroy might leak memory Defer semantic3 running of generated `opAssign` function, and add special error gagging mechanism in `FuncDeclaration.semantic3()` to hide errors from its body. https://github.com/D-Programming-Language/dmd/commit/af4d3a4158f95d1720b42e8027ae2aead90c7a4f Merge pull request #5075 from 9rnsr/fix15044 [REG2.068.0] Issue 15044 - destroy might leak memory
Comment #6 by github-bugzilla — 2015-09-24T08:15:59Z