Browse Source

fs: fix assert in fs.watch()

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.
v0.8.11-release
Ben Noordhuis 12 years ago
parent
commit
db5c26e3b5
  1. 15
      src/fs_event_wrap.cc

15
src/fs_event_wrap.cc

@ -166,12 +166,17 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
Handle<Value> FSEventWrap::Close(const Arguments& args) { Handle<Value> FSEventWrap::Close(const Arguments& args) {
HandleScope scope; HandleScope scope;
UNWRAP(FSEventWrap) // Unwrap manually here. The UNWRAP() macro asserts that wrap != NULL.
// That usually indicates an error but not here: double closes are possible
if (!wrap->initialized_) // and legal, HandleWrap::Close() deals with them the same way.
return Undefined(); 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; wrap->initialized_ = false;
return HandleWrap::Close(args); return HandleWrap::Close(args);
} }

Loading…
Cancel
Save