Skip to content
Browse files

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.
  • Loading branch information...
1 parent 07804c7 commit db5c26e3b57c5c0c5c3e84931bc73b701f0258d1 @bnoordhuis bnoordhuis committed
Showing with 10 additions and 5 deletions.
  1. +10 −5 src/fs_event_wrap.cc
View
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) {
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);
}

0 comments on commit db5c26e

Please sign in to comment.
Something went wrong with that request. Please try again.