From d5d043f2d72e88669e2e3621651153316831034e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 9 Jan 2012 20:39:06 +0100 Subject: [PATCH] handle_wrap: guard against uninitialized handle or double close --- src/handle_wrap.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 5b6594a3a90..eb6713edad9 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -99,9 +99,11 @@ Handle HandleWrap::Close(const Arguments& args) { UNWRAP + // guard against uninitialized handle or double close + if (wrap->handle__ == NULL) return v8::Null(); assert(!wrap->object_.IsEmpty()); uv_close(wrap->handle__, OnClose); - + wrap->handle__ = NULL; HandleWrap::Ref(args); @@ -143,6 +145,9 @@ void HandleWrap::OnClose(uv_handle_t* handle) { // The wrap object should still be there. assert(wrap->object_.IsEmpty() == false); + // But the handle pointer should be gone. + assert(wrap->handle__ == NULL); + wrap->object_->SetPointerInInternalField(0, NULL); wrap->object_.Dispose(); wrap->object_.Clear();