From 27e0019e44a94d9fe0cfd3abb83e49295cf58ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Fri, 19 Feb 2016 21:18:22 +0100 Subject: [PATCH] Fix regression in FreeListRef where no memory was allocated for the ref count. Fixes #1432. Commit 6be5471 switched FreeListRef to use FreeListObjectAlloc underneath, but didn't accound for the extra memory that is needed to store the reference count directly after the object payload. The possible implications of this are memory corruption and memory leaks, although with the predefined allocator setip, this will only happen to types with a POT size or slightly less. This commit adds an "EXTRA" template type parameter to FreeListObjectAlloc that is used to determine the additional amount of allocated memory, which is set to "int" in the case of FreeListRef. (cherry picked from commit d78a9ce89b845e4f89a84bd70bbd48c7595463d4) (cherry picked from commit 613d15926e241c03e75bb2d237d39ba712613aeb) --- source/vibe/internal/memory.d | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/vibe/internal/memory.d b/source/vibe/internal/memory.d index c2f8524..8e40570 100644 --- a/source/vibe/internal/memory.d +++ b/source/vibe/internal/memory.d @@ -611,10 +611,10 @@ nothrow: } } -struct FreeListObjectAlloc(T, bool USE_GC = true, bool INIT = true) +struct FreeListObjectAlloc(T, bool USE_GC = true, bool INIT = true, EXTRA = void) { enum ElemSize = AllocSize!T; - enum ElemSlotSize = max(AllocSize!T, Slot.sizeof); + enum ElemSlotSize = max(AllocSize!T + AllocSize!EXTRA, Slot.sizeof); static if( is(T == class) ){ alias TR = T; @@ -675,7 +675,7 @@ template AllocSize(T) struct FreeListRef(T, bool INIT = true) { - alias ObjAlloc = FreeListObjectAlloc!(T, true, INIT); + alias ObjAlloc = FreeListObjectAlloc!(T, true, INIT, int); enum ElemSize = AllocSize!T; static if( is(T == class) ){