summaryrefslogtreecommitdiff
path: root/test/addons/uv-handle-leak/binding.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/addons/uv-handle-leak/binding.cc')
-rw-r--r--test/addons/uv-handle-leak/binding.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/addons/uv-handle-leak/binding.cc b/test/addons/uv-handle-leak/binding.cc
new file mode 100644
index 0000000000..c2e5f0bf27
--- /dev/null
+++ b/test/addons/uv-handle-leak/binding.cc
@@ -0,0 +1,48 @@
+#include <node.h>
+#include <v8.h>
+#include <uv.h>
+
+using v8::Context;
+using v8::FunctionCallbackInfo;
+using v8::Isolate;
+using v8::Local;
+using v8::Object;
+using v8::Value;
+
+// Give these things names in the public namespace so that we can see
+// them show up in symbol dumps.
+void CloseCallback(uv_handle_t* handle) {}
+
+class ExampleOwnerClass {
+ public:
+ virtual ~ExampleOwnerClass() {}
+};
+
+ExampleOwnerClass example_instance;
+
+void LeakHandle(const FunctionCallbackInfo<Value>& args) {
+ Isolate* isolate = args.GetIsolate();
+ Local<Context> context = isolate->GetCurrentContext();
+ uv_loop_t* loop = node::GetCurrentEventLoop(isolate);
+ assert(loop != nullptr);
+
+ uv_timer_t* leaked_timer = new uv_timer_t;
+ leaked_timer->close_cb = CloseCallback;
+
+ if (args[0]->IsNumber()) {
+ leaked_timer->data =
+ reinterpret_cast<void*>(args[0]->IntegerValue(context).FromJust());
+ } else {
+ leaked_timer->data = &example_instance;
+ }
+
+ uv_timer_init(loop, leaked_timer);
+ uv_timer_start(leaked_timer, [](uv_timer_t*){}, 1000, 1000);
+ uv_unref(reinterpret_cast<uv_handle_t*>(leaked_timer));
+}
+
+void Initialize(v8::Local<v8::Object> exports) {
+ NODE_SET_METHOD(exports, "leakHandle", LeakHandle);
+}
+
+NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)