diff options
author | Trevor Norris <trev.norris@gmail.com> | 2014-11-26 12:27:57 -0800 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2014-11-26 12:27:57 -0800 |
commit | 0d051238be2e07e671d7d9f4f444e0cc1efadf1b (patch) | |
tree | 01870bda2042c73c5bd1d51659e5f6ca9bbefd52 | |
parent | 3a08b7c3e0bc6757e7088919695336ab94c3b415 (diff) | |
download | node-0d051238be2e07e671d7d9f4f444e0cc1efadf1b.tar.gz |
timers: fix unref() memory leak
The destructor isn't being called for timers that have been unref'd.
Fixes: https://github.com/joyent/node/issues/8364
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
-rw-r--r-- | icu_config.gypi | 2 | ||||
-rw-r--r-- | lib/timers.js | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/icu_config.gypi b/icu_config.gypi new file mode 100644 index 000000000..a21b0ceaf --- /dev/null +++ b/icu_config.gypi @@ -0,0 +1,2 @@ +# Do not edit. Generated by the configure script. +{ 'variables': { }} diff --git a/lib/timers.js b/lib/timers.js index be39ea66d..1893f1978 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -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) { @@ -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(); |