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
  • Loading branch information
trevnorris authored and indutny committed Apr 3, 2015
1 parent 4a801c2 commit 340be32
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ const Timeout = function(after) {
this._repeat = null;
};


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


Timeout.prototype.unref = function() {
if (this._handle) {
this._handle.unref();
Expand All @@ -315,7 +323,8 @@ Timeout.prototype.unref = function() {
if (this._called && !this._repeat) return;

this._handle = new Timer();
this._handle[kOnTimeout] = this._onTimeout;
this._handle.owner = this;
this._handle[kOnTimeout] = unrefdHandle;
this._handle.start(delay, 0);
this._handle.domain = this.domain;
this._handle.unref();
Expand Down

0 comments on commit 340be32

Please sign in to comment.