From 09d9ea47bf8964199f53a8f996eaab3c7a8cb506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 10 Dec 2016 14:21:57 +0100 Subject: [PATCH] Fix InterfaceProxy to not explicitly destroy contained class instances. This lead to double-destruction in case an InterfaceProxy was copied. --- source/vibe/internal/interfaceproxy.d | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/source/vibe/internal/interfaceproxy.d b/source/vibe/internal/interfaceproxy.d index 9133d50..584c77f 100644 --- a/source/vibe/internal/interfaceproxy.d +++ b/source/vibe/internal/interfaceproxy.d @@ -98,6 +98,7 @@ struct InterfaceProxy(I) if (is(I == interface)) { if (m_intf) { m_intf._destroy(m_value); m_intf = null; + () @trusted { (cast(ubyte[])m_value)[] = 0; } (); } } @@ -210,26 +211,31 @@ struct InterfaceProxy(I) if (is(I == interface)) { return impl; } - void _destroy(void[] stor) + override void _destroy(void[] stor) @trusted nothrow { - try destroy(_extract(stor)); - catch (Exception e) assert(false, "Destructor has thrown: "~e.msg); + static if (is(O == struct)) { + try destroy(_extract(stor)); + catch (Exception e) assert(false, "Destructor has thrown: "~e.msg); + } } - void _postblit(void[] stor) + override void _postblit(void[] stor) @trusted nothrow { - try typeid(O).postblit(stor.ptr); - catch (Exception e) assert(false, "Postblit contructor has thrown: "~e.msg); + static if (is(O == struct)) { + try typeid(O).postblit(stor.ptr); + catch (Exception e) assert(false, "Postblit contructor has thrown: "~e.msg); + } } - TypeInfo _typeInfo() + override TypeInfo _typeInfo() @safe nothrow { return typeid(O); } static ref inout(O) _extract(inout(void)[] stor) @trusted nothrow pure @nogc { - return (cast(inout(O)[])stor[0 .. O.sizeof])[0]; + if (stor.length < O.sizeof) assert(false); + return *cast(inout(O)*)stor.ptr; } mixin methodDefs!0;