Skip to content

Commit

Permalink
server: fix ws memory leak (fixes #268)
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchg committed Jul 30, 2014
1 parent f00ef8b commit 01e173c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/server.js
Expand Up @@ -49,7 +49,7 @@ function Server(opts){
if (~this.transports.indexOf('websocket')) {
this.ws = new WebSocketServer({ noServer: true, clientTracking: false });
}
};
}

/**
* Protocol errors mappings.
Expand Down Expand Up @@ -268,7 +268,7 @@ Server.prototype.handshake = function(transport, req){
* @api public
*/

Server.prototype.handleUpgrade = function(req, socket, head){
Server.prototype.handleUpgrade = function(req, socket, upgradeHead){
this.prepare(req);

var self = this;
Expand All @@ -278,8 +278,12 @@ Server.prototype.handleUpgrade = function(req, socket, head){
return;
}

var head = new Buffer(upgradeHead.length);
upgradeHead.copy(head);
upgradeHead = null;

// delegate to ws
self.ws.handleUpgrade(req, socket, head, function(conn){
self.ws.handleUpgrade(req, socket, upgradeHead, function(conn){

This comment has been minimized.

Copy link
@nicokaiser

nicokaiser Jul 30, 2014

Contributor

Is this really wanted? upgradeHead is set to null just before... Shouldn't this stay head?

This comment has been minimized.

Copy link
@rase-

rase- Aug 1, 2014

Contributor

Thanks @nicokaiser! In case you didn't notice: 681b4fc :)

This comment has been minimized.

Copy link
@nicokaiser

nicokaiser Aug 1, 2014

Contributor

Great, thanks!

self.onWebSocket(req, conn);
});
});
Expand Down

0 comments on commit 01e173c

Please sign in to comment.