mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
timers: fix memory leak in setTimeout
Closing handle is leaked when setTimeout called with arguments which are 1. a callback 2. zero delay (i.e. setTimeout(function(){}, 0); )
This commit is contained in:
parent
6df7bdd954
commit
f2f30286bf
2 changed files with 7 additions and 1 deletions
|
@ -151,7 +151,10 @@ exports.setTimeout = function(callback, after) {
|
|||
timer = new Timer();
|
||||
|
||||
if (arguments.length <= 2) {
|
||||
timer._onTimeout = callback;
|
||||
timer._onTimeout = function() {
|
||||
callback();
|
||||
timer.close();
|
||||
}
|
||||
} else {
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
timer._onTimeout = function() {
|
||||
|
|
|
@ -27,6 +27,7 @@ var assert = require('assert');
|
|||
var ncalled = 0;
|
||||
|
||||
setTimeout(f, 0, 'foo', 'bar', 'baz');
|
||||
var timer = setTimeout(function(){}, 0);
|
||||
|
||||
function f(a, b, c) {
|
||||
assert.equal(a, 'foo');
|
||||
|
@ -37,6 +38,8 @@ var assert = require('assert');
|
|||
|
||||
process.on('exit', function() {
|
||||
assert.equal(ncalled, 1);
|
||||
// timer should be already closed
|
||||
assert.equal(timer.close(), -1);
|
||||
});
|
||||
})();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue