Skip to content

Commit 207e48c

Browse files
yosuke-furukawabnoordhuis
authored andcommitted
dgram: check close callback is function
PR-URL: #609 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 6ac8bdc commit 207e48c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/dgram.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ function afterSend(err) {
341341

342342

343343
Socket.prototype.close = function(callback) {
344-
if (callback)
344+
if (typeof callback === 'function')
345345
this.on('close', callback);
346346
this._healthCheck();
347347
this._stopReceiving();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var assert = require('assert');
2+
var common = require('../common');
3+
var dgram = require('dgram');
4+
5+
var buf = new Buffer(1024);
6+
buf.fill(42);
7+
8+
var socket = dgram.createSocket('udp4');
9+
var closeEvents = 0;
10+
socket.send(buf, 0, buf.length, common.PORT, 'localhost');
11+
12+
// if close callback is not function, ignore the argument.
13+
socket.close('bad argument');
14+
15+
socket.on('close', function() {
16+
++closeEvents;
17+
});
18+
19+
process.on('exit', function() {
20+
assert.equal(closeEvents, 1);
21+
});

0 commit comments

Comments
 (0)