Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free TCPContext on connection failure - fixes #1321 #1322

Merged
merged 1 commit into from
Nov 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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