src: fix memory leak in UsingDomains()
authorBen Noordhuis <info@bnoordhuis.nl>
Fri, 5 Jul 2013 00:20:37 +0000 (02:20 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Fri, 5 Jul 2013 00:20:39 +0000 (02:20 +0200)
UsingDomains() assigned process_tickCallback when it had already
been set by MakeCallback() a few frames down the call stack.

Dispose the handle first or we'll retain whatever is in the lexical
closure of the old process._tickCallback function.

Fixes #5795.

src/node.cc

index 9b27bfd..94af509 100644 (file)
@@ -919,6 +919,7 @@ Handle<Value> UsingDomains(const Arguments& args) {
   Local<Function> ndt = ndt_v.As<Function>();
   process->Set(String::New("_tickCallback"), tdc);
   process->Set(String::New("nextTick"), ndt);
+  process_tickCallback.Dispose();  // Possibly already set by MakeCallback().
   process_tickCallback = Persistent<Function>::New(tdc);
   return Undefined();
 }