Skip to content

Commit

Permalink
Merge pull request #42 from vibe-d/fix_http_exchange_leaks
Browse files Browse the repository at this point in the history
Fix leaked exchange objects during HTTP connection handling
  • Loading branch information
l-kramer committed Sep 14, 2024
2 parents a95c66b + b9dac68 commit 63472bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion source/vibe/http/internal/http1/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void handleHTTP1Connection(TLSStreamType)(TCPConnection connection, TLSStreamTyp

private bool handleRequest(TLSStreamType, Allocator)(StreamProxy http_stream, TCPConnection tcp_connection, HTTPServerContext listen_info, ref HTTPServerSettings settings, ref bool keep_alive, scope Allocator request_allocator)
@safe {
import vibe.container.internal.utilallocator : make;
import vibe.container.internal.utilallocator : make, dispose;
import vibe.http.internal.utils : formatRFC822DateAlloc;
import std.algorithm.searching : canFind, startsWith;
import std.conv : parse, to;
Expand Down Expand Up @@ -104,6 +104,7 @@ private bool handleRequest(TLSStreamType, Allocator)(StreamProxy http_stream, TC
// Create the response object
ConnectionStreamProxy cproxy = tcp_connection;
auto exchange = () @trusted { return request_allocator.make!HTTP1ServerExchange(http_stream, cproxy); } ();
scope (exit) () @trusted { request_allocator.dispose(exchange); } ();
auto res = FreeListRef!HTTPServerResponse(exchange, settings, request_allocator/*.Scoped_payload*/);
req.tls = res.m_tls = listen_info.tlsContext !is null;
if (req.tls) {
Expand Down
4 changes: 3 additions & 1 deletion source/vibe/http/internal/http2/exchange.d
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ bool handleHTTP2Request(UStream)(ref HTTP2ConnectionStream!UStream stream,

// initialize request
auto req = () @trusted { return alloc.make!HTTPServerRequest(reqtime, listen_info.bindPort); } ();
scope (exit) () @trusted { alloc.dispose(req); } ();
// store the IP address
req.clientAddress = tcp_connection.remoteAddress;

Expand Down Expand Up @@ -251,8 +252,9 @@ bool handleHTTP2Request(UStream)(ref HTTP2ConnectionStream!UStream stream,

auto exchange = () @trusted { return alloc.make!(HTTP2ServerExchange!UStream)(stream,
tcpc, h2context, headers, table, alloc); } ();
scope (exit) () @trusted { destroy(exchange); } ();
scope (exit) () @trusted { alloc.dispose(exchange); } ();
auto res = () @trusted { return alloc.make!HTTPServerResponse(exchange, settings, alloc); } ();
scope (exit) () @trusted { alloc.dispose(res); } ();
res.httpVersion = HTTPVersion.HTTP_2;

// setup compressed output
Expand Down

0 comments on commit 63472bf

Please sign in to comment.