diff options
author | Timothy Gu <timothygu99@gmail.com> | 2017-12-03 05:37:56 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-12-13 08:32:55 +0300 |
commit | cd71fc1545db30ca8589ddf1933167286308ad8f (patch) | |
tree | bf864e6ac504a38a237ef49d49dc80c15fa863cf /src | |
parent | 11ebaff15c39e87aa2850b43847627aff8e6f62e (diff) |
src: make FSEventWrap/StatWatcher::Start more robust
PR-URL: https://github.com/nodejs/node/pull/17432
Fixes: https://github.com/nodejs/node/issues/17430
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/fs_event_wrap.cc | 3 | ||||
-rw-r--r-- | src/node_stat_watcher.cc | 8 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 934b9d545c6..85a09060a11 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -111,7 +111,8 @@ void FSEventWrap::Start(const FunctionCallbackInfo<Value>& args) { FSEventWrap* wrap; ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder()); - CHECK_EQ(wrap->initialized_, false); + if (wrap->initialized_) + return args.GetReturnValue().Set(0); static const char kErrMsg[] = "filename must be a string or Buffer"; if (args.Length() < 1) diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index cb48c652c97..9aa0c950591 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -111,9 +111,15 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) { const bool persistent = args[1]->BooleanValue(); const uint32_t interval = args[2]->Uint32Value(); - if (!persistent) + if (uv_is_active(reinterpret_cast<uv_handle_t*>(wrap->watcher_))) + return; + // Safe, uv_ref/uv_unref are idempotent. + if (persistent) + uv_ref(reinterpret_cast<uv_handle_t*>(wrap->watcher_)); + else uv_unref(reinterpret_cast<uv_handle_t*>(wrap->watcher_)); uv_fs_poll_start(wrap->watcher_, Callback, *path, interval); + wrap->ClearWeak(); } |