Skip to content

Commit

Permalink
tls_wrap: fix this incredibly stupid leak
Browse files Browse the repository at this point in the history
Always call `Done` on the WriteWrap, and ensure that `EncOut` will
consume all data in clear_in_ and invoke queued callbacks.

Fix: #1075
  • Loading branch information
indutny committed Mar 25, 2015
1 parent 16a13c7 commit 3327932
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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_);
}
}


Expand All @@ -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();
Expand Down

0 comments on commit 3327932

Please sign in to comment.