Skip to content

Commit

Permalink
Don't free GC allocated memory in HTTP server.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
s-ludwig committed Jun 16, 2017
1 parent ae511ac commit 4869b2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions http/vibe/http/server.d
Expand Up @@ -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);
} ();
Expand Down
8 changes: 5 additions & 3 deletions utils/vibe/internal/utilallocator.d
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 4869b2b

Please sign in to comment.