Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
handle_wrap: guard against uninitialized handle or double close
  • Loading branch information
bnoordhuis committed Jan 9, 2012
1 parent cc5cea3 commit d5d043f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/handle_wrap.cc
Expand Up @@ -99,9 +99,11 @@ Handle<Value> 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);

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d5d043f

Please sign in to comment.