From db5c26e3b57c5c0c5c3e84931bc73b701f0258d1 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 14 Sep 2012 02:34:10 +0200 Subject: [PATCH] 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. --- src/fs_event_wrap.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index adac00c9fc..bb45733007 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -166,12 +166,17 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename, Handle 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(ptr); + + if (wrap == NULL || wrap->initialized_ == false) return Undefined(); wrap->initialized_ = false; + return HandleWrap::Close(args); }