Skip to content

Commit 0e06197

Browse files
trevnorrisindutny
authored andcommitted
timers: fix unref() memory leak
The destructor isn't being called for timers that have been unref'd. Fixes: nodejs/node-v0.x-archive#8364 PR-URL: #1330 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent b6e22c4 commit 0e06197

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/timers.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ const Timeout = function(after) {
301301
this._repeat = null;
302302
};
303303

304+
305+
function unrefdHandle() {
306+
this.owner._onTimeout();
307+
if (!this.owner.repeat)
308+
this.owner.close();
309+
}
310+
311+
304312
Timeout.prototype.unref = function() {
305313
if (this._handle) {
306314
this._handle.unref();
@@ -315,7 +323,8 @@ Timeout.prototype.unref = function() {
315323
if (this._called && !this._repeat) return;
316324

317325
this._handle = new Timer();
318-
this._handle[kOnTimeout] = this._onTimeout;
326+
this._handle.owner = this;
327+
this._handle[kOnTimeout] = unrefdHandle;
319328
this._handle.start(delay, 0);
320329
this._handle.domain = this.domain;
321330
this._handle.unref();

0 commit comments

Comments
 (0)