Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fs: don't close uninitialized fs.watch handle

Makes uv_close() assert because the uv_fs_event_t struct contains garbage.
  • Loading branch information...
commit 8dd4fcbe8f396fbc14a92a30ebb86c781b38e3dd 1 parent f84d86b
@bnoordhuis bnoordhuis authored
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/fs_event_wrap.cc
View
20 src/fs_event_wrap.cc
@@ -45,6 +45,7 @@ class FSEventWrap: public HandleWrap {
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments& args);
static Handle<Value> Start(const Arguments& args);
+ static Handle<Value> Close(const Arguments& args);
private:
FSEventWrap(Handle<Object> object);
@@ -54,16 +55,19 @@ class FSEventWrap: public HandleWrap {
int status);
uv_fs_event_t handle_;
+ bool initialized_;
};
FSEventWrap::FSEventWrap(Handle<Object> object): HandleWrap(object,
(uv_handle_t*)&handle_) {
handle_.data = reinterpret_cast<void*>(this);
+ initialized_ = false;
}
FSEventWrap::~FSEventWrap() {
+ assert(initialized_ == false);
}
@@ -111,6 +115,7 @@ Handle<Value> FSEventWrap::Start(const Arguments& args) {
if (!args[1]->IsTrue()) {
uv_unref(uv_default_loop());
}
+ wrap->initialized_ = true;
} else {
SetErrno(uv_last_error(uv_default_loop()));
}
@@ -150,6 +155,21 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
MakeCallback(wrap->object_, "onchange", 3, argv);
}
+
+
+Handle<Value> FSEventWrap::Close(const Arguments& args) {
+ HandleScope scope;
+
+ UNWRAP
+
+ if (!wrap->initialized_)
+ return Undefined();
+
+ wrap->initialized_ = false;
+ return HandleWrap::Close(args);
+}
+
+
} // namespace node
NODE_MODULE(node_fs_event_wrap, node::FSEventWrap::Initialize)
Please sign in to comment.
Something went wrong with that request. Please try again.