Skip to content

Commit 3327932

Browse files
committed
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: #1075
1 parent 16a13c7 commit 3327932

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/tls_wrap.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ TLSWrap::~TLSWrap() {
9090
MakePending();
9191

9292
// And destroy
93-
while (WriteItem* wi = pending_write_items_.PopFront())
93+
while (WriteItem* wi = pending_write_items_.PopFront()) {
94+
wi->w_->Done(UV_ECANCELED);
9495
delete wi;
96+
}
9597

9698
ClearError();
9799
}
@@ -310,10 +312,12 @@ void TLSWrap::EncOut() {
310312
write_req->Dispatched();
311313

312314
// Ignore errors, this should be already handled in js
313-
if (err)
315+
if (err) {
314316
write_req->Dispose();
315-
else
317+
InvokeQueued(err);
318+
} else {
316319
NODE_COUNT_NET_BYTES_SENT(write_size_);
320+
}
317321
}
318322

319323

@@ -335,6 +339,9 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
335339
// Commit
336340
NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_);
337341

342+
// Ensure that the progress will be maed and `InvokeQueued` will be called
343+
wrap->ClearIn();
344+
338345
// Try writing more data
339346
wrap->write_size_ = 0;
340347
wrap->EncOut();

0 commit comments

Comments
 (0)