From 4d8d08b27ded7a66c047cf90d649c89e819ae30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 24 Oct 2018 21:05:45 +0200 Subject: [PATCH] Fix destruction code in ChoppedVector. --- source/eventcore/internal/utils.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/eventcore/internal/utils.d b/source/eventcore/internal/utils.d index 2613522..03223cf 100644 --- a/source/eventcore/internal/utils.d +++ b/source/eventcore/internal/utils.d @@ -39,6 +39,8 @@ void freeT(T)(ref T inst) @nogc { import core.stdc.stdlib : free; + if (!inst) return; + noGCDestroy(inst); static if (hasIndirections!T) GC.removeRange(cast(void*)inst); @@ -151,12 +153,13 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { @nogc { () @trusted { foreach (i; 0 .. m_chunkCount) { - destroy(m_chunks[i]); + destroy(*m_chunks[i]); static if (hasIndirections!T) GC.removeRange(m_chunks[i]); free(m_chunks[i]); } free(m_chunks.ptr); + m_chunks = null; } (); m_chunkCount = 0; m_length = 0;