Skip to content

Commit

Permalink
timers: fix unref() memory leak
Browse files Browse the repository at this point in the history
The destructor isn't being called for timers that have been unref'd.

Fixes: nodejs/node-v0.x-archive#8364
Signed-off-by: Trevor Norris <[email protected]>
  • Loading branch information
trevnorris committed Nov 26, 2014
1 parent 3a08b7c commit 0d05123
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions icu_config.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Do not edit. Generated by the configure script.
{ 'variables': { }}
11 changes: 10 additions & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ var Timeout = function(after) {
this._repeat = false;
};


function unrefdHandle() {
this.owner._onTimeout();
if (!this.owner.repeat)
this.owner.close();
}


Timeout.prototype.unref = function() {
if (!this._handle) {

Expand All @@ -303,7 +311,8 @@ Timeout.prototype.unref = function() {
if (delay < 0) delay = 0;
exports.unenroll(this);
this._handle = new Timer();
this._handle.ontimeout = this._onTimeout;
this._handle.owner = this;
this._handle.ontimeout = unrefdHandle;
this._handle.start(delay, 0);
this._handle.domain = this.domain;
this._handle.unref();
Expand Down

0 comments on commit 0d05123

Please sign in to comment.