diff options
-rw-r--r-- | src/handle_wrap.cc | 6 | ||||
-rw-r--r-- | src/handle_wrap.h | 6 | ||||
-rw-r--r-- | src/stream_wrap.cc | 15 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 595ea7d3a53..3e348a8b258 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -43,7 +43,7 @@ using v8::Value; void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) { HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); - if (wrap != nullptr && wrap->handle__ != nullptr) { + if (IsAlive(wrap)) { uv_ref(wrap->handle__); wrap->flags_ &= ~kUnref; } @@ -53,7 +53,7 @@ void HandleWrap::Ref(const FunctionCallbackInfo<Value>& args) { void HandleWrap::Unref(const FunctionCallbackInfo<Value>& args) { HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); - if (wrap != nullptr && wrap->handle__ != nullptr) { + if (IsAlive(wrap)) { uv_unref(wrap->handle__); wrap->flags_ |= kUnref; } @@ -66,7 +66,7 @@ void HandleWrap::Close(const FunctionCallbackInfo<Value>& args) { HandleWrap* wrap = Unwrap<HandleWrap>(args.Holder()); // guard against uninitialized handle or double close - if (wrap == nullptr || wrap->handle__ == nullptr) + if (!IsAlive(wrap)) return; CHECK_EQ(false, wrap->persistent().IsEmpty()); diff --git a/src/handle_wrap.h b/src/handle_wrap.h index 40ee75cd811..13457e7cc53 100644 --- a/src/handle_wrap.h +++ b/src/handle_wrap.h @@ -57,7 +57,11 @@ class HandleWrap : public AsyncWrap { static void Ref(const v8::FunctionCallbackInfo<v8::Value>& args); static void Unref(const v8::FunctionCallbackInfo<v8::Value>& args); - inline uv_handle_t* GetHandle() { return handle__; } + static inline bool IsAlive(const HandleWrap* wrap) { + return wrap != nullptr && wrap->GetHandle() != nullptr; + } + + inline uv_handle_t* GetHandle() const { return handle__; } protected: HandleWrap(Environment* env, diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index a6c64ac8bd4..103d1e30381 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -90,6 +90,9 @@ void StreamWrap::UpdateWriteQueueSize() { void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) { StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); + if (!IsAlive(wrap)) + return args.GetReturnValue().Set(UV_EINVAL); + int err = uv_read_start(wrap->stream(), OnAlloc, OnRead); args.GetReturnValue().Set(err); } @@ -97,6 +100,8 @@ void StreamWrap::ReadStart(const FunctionCallbackInfo<Value>& args) { void StreamWrap::ReadStop(const FunctionCallbackInfo<Value>& args) { StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); + if (!IsAlive(wrap)) + return args.GetReturnValue().Set(UV_EINVAL); int err = uv_read_stop(wrap->stream()); args.GetReturnValue().Set(err); } @@ -183,6 +188,8 @@ void StreamWrap::WriteBuffer(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); + if (!IsAlive(wrap)) + return args.GetReturnValue().Set(UV_EINVAL); CHECK(args[0]->IsObject()); CHECK(Buffer::HasInstance(args[1])); @@ -240,6 +247,8 @@ void StreamWrap::WriteStringImpl(const FunctionCallbackInfo<Value>& args) { int err; StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); + if (!IsAlive(wrap)) + return args.GetReturnValue().Set(UV_EINVAL); CHECK(args[0]->IsObject()); CHECK(args[1]->IsString()); @@ -367,6 +376,8 @@ void StreamWrap::Writev(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); + if (!IsAlive(wrap)) + return args.GetReturnValue().Set(UV_EINVAL); CHECK(args[0]->IsObject()); CHECK(args[1]->IsArray()); @@ -493,6 +504,8 @@ void StreamWrap::WriteBinaryString(const FunctionCallbackInfo<Value>& args) { void StreamWrap::SetBlocking(const FunctionCallbackInfo<Value>& args) { StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); + if (!IsAlive(wrap)) + return args.GetReturnValue().Set(UV_EINVAL); CHECK_GT(args.Length(), 0); int err = uv_stream_set_blocking(wrap->stream(), args[0]->IsTrue()); args.GetReturnValue().Set(err); @@ -537,6 +550,8 @@ void StreamWrap::Shutdown(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); StreamWrap* wrap = Unwrap<StreamWrap>(args.Holder()); + if (!IsAlive(wrap)) + return args.GetReturnValue().Set(UV_EINVAL); CHECK(args[0]->IsObject()); Local<Object> req_wrap_obj = args[0].As<Object>(); |