]> git.wh0rd.org Git - chrome-ext/music-player-client.git/commitdiff
tcp-client: do not leak sockets
authorMike Frysinger <vapier@gentoo.org>
Sat, 28 Sep 2013 05:06:10 +0000 (01:06 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 28 Sep 2013 05:06:10 +0000 (01:06 -0400)
If one object has connect() called more than once (like when reconnecting),
make sure we destroy the previous socket rather than leaking it.

js/tcp-client.js

index ec61399b49ce12b1be0a3e15422a5f417b3da71f..dd0c189dc62a7a711bd11c8cfbf649b854b5b0eb 100644 (file)
@@ -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));