Bug 20476 – chainTogether leaks exception with -dip1008

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-01-02T16:59:30Z
Last change time
2020-01-03T00:22:20Z
Keywords
pull
Assigned to
No Owner
Creator
moonlightsentinel

Comments

Comment #0 by moonlightsentinel — 2020-01-02T16:59:30Z
Test case: class E : Exception { static int instances; this() { super("MSG"); instances++; } ~this() { instances--; } } void main() { try { throw new E(); } catch (Throwable e) { assert(E.instances == 1); } assert(E.instances == 0); try { throw new E(); } catch (Throwable e) { assert(E.instances == 1); e = Exception.chainTogether(null, e); // Returns e unchanged } assert(E.instances == 0); } The last assert fails because chainTogether returns e directly (due to the first throwable being null) but increments the refcount anyway
Comment #1 by dlang-bot — 2020-01-02T19:07:11Z
@MoonlightSentinel created dlang/druntime pull request #2892 "Fix Issue 20476 - chainTogether leaks exception with -dip1008" fixing this issue: - Fix Issue 20476 - chainTogether leaks exception with -dip1008 chainTogether unconditionally incremented the refcount of the second throwable, even if it was returned without being chained to the first https://github.com/dlang/druntime/pull/2892
Comment #2 by dlang-bot — 2020-01-03T00:22:20Z
dlang/druntime pull request #2892 "Fix Issue 20476 - chainTogether leaks exception with -dip1008" was merged into master: - d97216f442c62f52649600ef380b6b5b71d5b4c6 by MoonlightSentinel: Fix Issue 20476 - chainTogether leaks exception with -dip1008 chainTogether unconditionally incremented the refcount of the second throwable, even if it was returned without being chained to the first https://github.com/dlang/druntime/pull/2892