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

Commit

Permalink
fs: fix assert in fs.watch()
Browse files Browse the repository at this point in the history
Fix the following error:

  FSEventWrap: Aborting due to unwrap failure at ../../src/fs_event_wrap.cc:169

It's possible and legal for a handle to be closed twice. HandleWrap::Close()
deals with that by ignoring the second close. Now FSEventWrap::Close() does
too.

Fixes #3997.
  • Loading branch information
bnoordhuis committed Sep 14, 2012
1 parent 07804c7 commit db5c26e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,17 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
Handle<Value> FSEventWrap::Close(const Arguments& args) {
HandleScope scope;

UNWRAP(FSEventWrap)

if (!wrap->initialized_)
return Undefined();

// Unwrap manually here. The UNWRAP() macro asserts that wrap != NULL.
// That usually indicates an error but not here: double closes are possible
// and legal, HandleWrap::Close() deals with them the same way.
assert(!args.Holder().IsEmpty());
assert(args.Holder()->InternalFieldCount() > 0);
void* ptr = args.Holder()->GetPointerFromInternalField(0);
FSEventWrap* wrap = static_cast<FSEventWrap*>(ptr);

if (wrap == NULL || wrap->initialized_ == false) return Undefined();
wrap->initialized_ = false;

return HandleWrap::Close(args);
}

Expand Down

0 comments on commit db5c26e

Please sign in to comment.