tls: fix leak on `DoWrite()` errors
authorFedor Indutny <fedor@indutny.com>
Sat, 14 Mar 2015 04:40:48 +0000 (21:40 -0700)
committerFedor Indutny <fedor@indutny.com>
Sat, 14 Mar 2015 16:27:52 +0000 (09:27 -0700)
It is very unlikely to happen, but still the write request should be
disposed in case of immediate failure.

PR-URL: https://github.com/iojs/io.js/pull/1154
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
src/tls_wrap.cc

index 49523bc..0fab952 100644 (file)
@@ -306,11 +306,13 @@ void TLSWrap::EncOut() {
   uv_buf_t buf[ARRAY_SIZE(data)];
   for (size_t i = 0; i < count; i++)
     buf[i] = uv_buf_init(data[i], size[i]);
-  int r = stream_->DoWrite(write_req, buf, count, nullptr);
+  int err = stream_->DoWrite(write_req, buf, count, nullptr);
   write_req->Dispatched();
 
   // Ignore errors, this should be already handled in js
-  if (!r)
+  if (err)
+    write_req->Dispose();
+  else
     NODE_COUNT_NET_BYTES_SENT(write_size_);
 }