From 3327932bb6cf3fe6d1619df07b4a20ad257f4a61 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 24 Mar 2015 20:21:32 -0700 Subject: [PATCH] tls_wrap: fix this incredibly stupid leak Always call `Done` on the WriteWrap, and ensure that `EncOut` will consume all data in clear_in_ and invoke queued callbacks. Fix: https://github.com/iojs/io.js/issues/1075 --- src/tls_wrap.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 0a6be858038866..9b3459f8599d41 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -90,8 +90,10 @@ TLSWrap::~TLSWrap() { MakePending(); // And destroy - while (WriteItem* wi = pending_write_items_.PopFront()) + while (WriteItem* wi = pending_write_items_.PopFront()) { + wi->w_->Done(UV_ECANCELED); delete wi; + } ClearError(); } @@ -310,10 +312,12 @@ void TLSWrap::EncOut() { write_req->Dispatched(); // Ignore errors, this should be already handled in js - if (err) + if (err) { write_req->Dispose(); - else + InvokeQueued(err); + } else { NODE_COUNT_NET_BYTES_SENT(write_size_); + } } @@ -335,6 +339,9 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) { // Commit NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_); + // Ensure that the progress will be maed and `InvokeQueued` will be called + wrap->ClearIn(); + // Try writing more data wrap->write_size_ = 0; wrap->EncOut();