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
PR-URL: https://github.com/iojs/io.js/pull/1244
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Fedor Indutny 2015-03-24 20:21:32 -07:00
parent e74b5d278c
commit 2ccc8f3970

View File

@ -90,8 +90,7 @@ TLSWrap::~TLSWrap() {
MakePending(); MakePending();
// And destroy // And destroy
while (WriteItem* wi = pending_write_items_.PopFront()) InvokeQueued(UV_ECANCELED);
delete wi;
ClearError(); ClearError();
} }
@ -310,10 +309,12 @@ void TLSWrap::EncOut() {
write_req->Dispatched(); write_req->Dispatched();
// Ignore errors, this should be already handled in js // Ignore errors, this should be already handled in js
if (err) if (err) {
write_req->Dispose(); write_req->Dispose();
else InvokeQueued(err);
} else {
NODE_COUNT_NET_BYTES_SENT(write_size_); NODE_COUNT_NET_BYTES_SENT(write_size_);
}
} }
@ -335,6 +336,9 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
// Commit // Commit
NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_); NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_);
// Ensure that the progress will be made and `InvokeQueued` will be called.
wrap->ClearIn();
// Try writing more data // Try writing more data
wrap->write_size_ = 0; wrap->write_size_ = 0;
wrap->EncOut(); wrap->EncOut();