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:
authorAnna Henningsen <anna@addaleax.net>2017-09-04 23:02:55 +0300
committerAnna Henningsen <anna@addaleax.net>2018-05-10 15:15:16 +0300
commit17e289eca8f8398243df5c4006d80f7381fd08bc (patch)
tree781f1398f78aa4b602ae3fca8654c28576e70b52 /src/node_stat_watcher.cc
parent5c6cf30143f3191b043ba0b4e814768efa1069f7 (diff)
src: make CleanupHandles() tear down handles/reqs
Previously, handles would not be closed when the current `Environment` stopped, which is acceptable in a single-`Environment`-per-process situation, but would otherwise create memory and file descriptor leaks. Also, introduce a generic way to close handles via the `Environment::CloseHandle()` function, which automatically keeps track of whether a close callback has been called yet or not. Many thanks for Stephen Belanger for reviewing the original version of this commit in the Ayo.js project. Refs: https://github.com/ayojs/ayo/pull/85 PR-URL: https://github.com/nodejs/node/pull/19377 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_stat_watcher.cc')
-rw-r--r--src/node_stat_watcher.cc7
1 files changed, 1 insertions, 6 deletions
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc
index a2cfb1088c9..d8f8a6a3622 100644
--- a/src/node_stat_watcher.cc
+++ b/src/node_stat_watcher.cc
@@ -75,11 +75,6 @@ void StatWatcher::Initialize(Environment* env, Local<Object> target) {
}
-static void Delete(uv_handle_t* handle) {
- delete reinterpret_cast<uv_fs_poll_t*>(handle);
-}
-
-
StatWatcher::StatWatcher(Environment* env, Local<Object> wrap)
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_STATWATCHER),
watcher_(new uv_fs_poll_t) {
@@ -93,7 +88,7 @@ StatWatcher::~StatWatcher() {
if (IsActive()) {
Stop();
}
- uv_close(reinterpret_cast<uv_handle_t*>(watcher_), Delete);
+ env()->CloseHandle(watcher_, [](uv_fs_poll_t* handle) { delete handle; });
}