From: Mike Frysinger Date: Sat, 28 Sep 2013 05:06:10 +0000 (-0400) Subject: tcp-client: do not leak sockets X-Git-Tag: v3.2~1 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=c7400cad8000d7fd659ec3259e6bed1c2cdc9c0a;p=chrome-ext%2Fmusic-player-client.git tcp-client: do not leak sockets If one object has connect() called more than once (like when reconnecting), make sure we destroy the previous socket rather than leaking it. --- diff --git a/js/tcp-client.js b/js/tcp-client.js index ec61399..dd0c189 100644 --- a/js/tcp-client.js +++ b/js/tcp-client.js @@ -110,6 +110,9 @@ Author: Boris Smus (smus@chromium.org) * @param {Object} createInfo The socket details */ TcpClient.prototype._onCreate = function(createInfo) { + if (this.socketId !== null) { + socket.destroy(this.socketId); + } this.socketId = createInfo.socketId; if (this.socketId > 0) { socket.connect(this.socketId, this.host, this.port, this._onConnectComplete.bind(this));