diff options
author | Timothy Gu <timothygu99@gmail.com> | 2017-12-02 18:37:56 -0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-12-13 06:32:55 +0100 |
commit | cd71fc1545db30ca8589ddf1933167286308ad8f (patch) | |
tree | bf864e6ac504a38a237ef49d49dc80c15fa863cf /src/node_stat_watcher.cc | |
parent | 11ebaff15c39e87aa2850b43847627aff8e6f62e (diff) | |
download | android-node-v8-cd71fc1545db30ca8589ddf1933167286308ad8f.tar.gz android-node-v8-cd71fc1545db30ca8589ddf1933167286308ad8f.tar.bz2 android-node-v8-cd71fc1545db30ca8589ddf1933167286308ad8f.zip |
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/node_stat_watcher.cc')
-rw-r--r-- | src/node_stat_watcher.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index cb48c652c9..9aa0c95059 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(); } |