Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2017-12-03 05:37:56 +0300
committerAnna Henningsen <anna@addaleax.net>2017-12-13 08:32:55 +0300
commitcd71fc1545db30ca8589ddf1933167286308ad8f (patch)
treebf864e6ac504a38a237ef49d49dc80c15fa863cf /src/node_stat_watcher.cc
parent11ebaff15c39e87aa2850b43847627aff8e6f62e (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/node_stat_watcher.cc')
-rw-r--r--src/node_stat_watcher.cc8
1 files changed, 7 insertions, 1 deletions
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();
}