From ea8969787cc7187ca1fd1783a06d8346f8fe92a0 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 16 Jun 2011 16:00:29 +0200 Subject: [PATCH] tcp_wrap: Don't return req object on error. --- src/tcp_wrap.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 4dcda455de..b06fb2f523 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -404,12 +404,15 @@ class TCPWrap { int r = uv_write(&req_wrap->req_, &buf, 1); - // Error starting the TCP. - if (r) SetErrno(uv_last_error().code); - wrap->UpdateWriteQueueSize(); - return scope.Close(req_wrap->object_); + if (r) { + SetErrno(uv_last_error().code); + delete req_wrap; + return scope.Close(v8::Null()); + } else { + return scope.Close(req_wrap->object_); + } } static void AfterConnect(uv_req_t* req, int status) { @@ -451,9 +454,13 @@ class TCPWrap { int r = uv_connect(&req_wrap->req_, address); - if (r) SetErrno(uv_last_error().code); - - return scope.Close(req_wrap->object_); + if (r) { + SetErrno(uv_last_error().code); + delete req_wrap; + return scope.Close(v8::Null()); + } else { + return scope.Close(req_wrap->object_); + } } uv_tcp_t handle_;