Skip to content

Commit

Permalink
Merge pull request #1322 from etcimon/patch-27
Browse files Browse the repository at this point in the history
Free TCPContext on connection failure - fixes #1321
  • Loading branch information
s-ludwig committed Nov 11, 2015
2 parents 9c2b8e8 + bda5675 commit 1602903
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion source/vibe/core/drivers/libevent2.d
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ final class Libevent2Driver : EventDriver {
if( !buf_event ) throw new Exception("Failed to create buffer event for socket.");

auto cctx = TCPContextAlloc.alloc(m_core, m_eventLoop, sockfd, buf_event, bind_addr, addr);
scope(failure) TCPContextAlloc.free(cctx);
bufferevent_setcb(buf_event, &onSocketRead, &onSocketWrite, &onSocketEvent, cctx);
if( bufferevent_enable(buf_event, EV_READ|EV_WRITE) )
throw new Exception("Error enabling buffered I/O event for socket.");
Expand Down Expand Up @@ -364,6 +365,7 @@ final class Libevent2Driver : EventDriver {
auto core = getThreadLibeventDriverCore();
// Add an event to wait for connections
auto ctx = TCPContextAlloc.alloc(core, evloop, handler_context.listenfd, null, handler_context.bind_addr, NetworkAddress());
scope(failure) TCPContextAlloc.free(ctx);
ctx.connectionCallback = handler_context.connection_callback;
ctx.listenEvent = event_new(evloop, handler_context.listenfd, EV_READ | EV_PERSIST, &onConnect, ctx);
ctx.listenOptions = handler_context.options;
Expand Down Expand Up @@ -889,7 +891,7 @@ final class Libevent2UDPConnection : UDPConnection {

// create a context for storing connection information
m_ctx = TCPContextAlloc.alloc(driver.m_core, driver.m_eventLoop, sockfd, null, bind_addr, NetworkAddress());

scope(failure) TCPContextAlloc.free(m_ctx);
m_ctx.listenEvent = event_new(driver.m_eventLoop, sockfd, EV_READ|EV_PERSIST, &onUDPRead, m_ctx);
if (!m_ctx.listenEvent) throw new Exception("Failed to create buffer event for socket.");
}
Expand Down

0 comments on commit 1602903

Please sign in to comment.