From 4869b2b8e9834a4dd990f917d35098a698360fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?So=CC=88nke=20Ludwig?= Date: Fri, 16 Jun 2017 22:06:06 +0200 Subject: [PATCH] Don't free GC allocated memory in HTTP server. In normal allocation mode (no VibeManualMemoryManagement), the GC allocated request memory was freed anyway, potentially resulting in dangling pointers if strings read from the request were stored outside of the request handler. This switches back to the proper behavior as in 0.7.x. --- http/vibe/http/server.d | 4 ++-- utils/vibe/internal/utilallocator.d | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/http/vibe/http/server.d b/http/vibe/http/server.d index 023eb6e432..64c1faa2b3 100644 --- a/http/vibe/http/server.d +++ b/http/vibe/http/server.d @@ -1774,9 +1774,9 @@ private void handleHTTPConnection(TCPConnection connection, HTTPListenInfo liste import vibe.internal.utilallocator: RegionListAllocator; version (VibeManualMemoryManagement) - scope request_allocator = new RegionListAllocator!(shared(Mallocator))(1024, Mallocator.instance); + scope request_allocator = new RegionListAllocator!(shared(Mallocator), false)(1024, Mallocator.instance); else - scope request_allocator = new RegionListAllocator!(shared(GCAllocator))(1024, GCAllocator.instance); + scope request_allocator = new RegionListAllocator!(shared(GCAllocator), true)(1024, GCAllocator.instance); handleRequest(http_stream, connection, listen_info, settings, keep_alive, request_allocator); } (); diff --git a/utils/vibe/internal/utilallocator.d b/utils/vibe/internal/utilallocator.d index 9632d3e253..22dfae5ac8 100644 --- a/utils/vibe/internal/utilallocator.d +++ b/utils/vibe/internal/utilallocator.d @@ -5,7 +5,7 @@ public import std.experimental.allocator.mallocator; public import std.experimental.allocator.building_blocks.affix_allocator; -final class RegionListAllocator(Allocator) : IAllocator { +final class RegionListAllocator(Allocator, bool leak = false) : IAllocator { import vibe.internal.memory_legacy : AllocSize, alignedSize; import std.algorithm.comparison : min, max; import std.conv : emplace; @@ -154,8 +154,10 @@ final class RegionListAllocator(Allocator) : IAllocator { Pool* pnext; for (auto p = cast(Pool*)m_freePools; p; p = pnext) { pnext = p.next; - m_baseAllocator.deallocate(p.data); - m_baseAllocator.deallocate((cast(void*)p)[0 .. AllocSize!Pool]); + static if (!leak) { + m_baseAllocator.deallocate(p.data); + m_baseAllocator.deallocate((cast(void*)p)[0 .. AllocSize!Pool]); + } } m_freePools = null;