From 8d1542f7fa4a3b32cc93634e19f181ebae967257 Mon Sep 17 00:00:00 2001 From: imaPheven Date: Tue, 5 Sep 2017 21:24:12 -0700 Subject: [PATCH] Null check on socket on error, the detach method is being called and when the close event is raised from _tls_wrap, it calls detach but the socket is already detached and is null. --- lib/poplib.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/poplib.js b/lib/poplib.js index 17a83ad..62464ee 100644 --- a/lib/poplib.js +++ b/lib/poplib.js @@ -100,9 +100,11 @@ function POP3Client(port, host, options) { var checkResp = true; var err = null; var detach = function() { + if (socket !== null) { socket.removeAllListeners("data"); socket.removeAllListeners("error"); socket.removeAllListeners("close"); + } }; socket.on("data", function(data) { @@ -640,4 +642,4 @@ POP3Client.prototype.quit = function(cb) { }); }; -module.exports = POP3Client; \ No newline at end of file +module.exports = POP3Client;