Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
trevnorris authored and indutny committed Apr 3, 2015
commit 340be322d207735f069103987e6928881248f526
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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will run this._handle.close() which runs uv_close(wrap->handle__, OnClose). Are we sure that the list of timers attached to this TimerWrap instance is empty before this runs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No list attached here for sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great. then LGTM.

}


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