Skip to content

Commit

Permalink
Merge pull request #2329 from vibe-d/redo_of_1324
Browse files Browse the repository at this point in the history
Free libevent TCP resources on finalize() and GC finalization.
  • Loading branch information
l-kramer committed Jun 29, 2019
2 parents f170a75 + 34b9406 commit c5bf5b3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions core/vibe/core/drivers/libevent2_tcp.d
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,13 @@ package final class Libevent2TCPConnection : TCPConnection {
} ();
}

/*~this()
{
//assert(m_ctx is null, "Leaking TCPContext because it has not been cleaned up and we are not allowed to touch the GC in finalizers..");
}*/
~this()
@trusted {
if (m_ctx && m_ctx.state == ConnectionState.passiveClose) {
if (m_ctx.event) bufferevent_free(m_ctx.event);
TCPContextAlloc.free(m_ctx);
}
}

@property void tcpNoDelay(bool enabled)
{
Expand Down Expand Up @@ -389,6 +392,14 @@ package final class Libevent2TCPConnection : TCPConnection {
void finalize()
{
flush();

if (m_ctx && m_ctx.state == ConnectionState.passiveClose) {
() @trusted {
if (m_ctx.event) bufferevent_free(m_ctx.event);
TCPContextAlloc.free(m_ctx);
} ();
m_ctx = null;
}
}

private bool fillReadBuffer(bool block, bool throw_on_fail = true, bool wait_for_timeout = false)
Expand Down

0 comments on commit c5bf5b3

Please sign in to comment.