server: fix ws memory leak (fixes #268)

This commit is contained in:
Guillermo Rauch
2014-07-29 17:35:32 -07:00
parent f00ef8b284
commit 01e173c8d5

View File

@@ -49,7 +49,7 @@ function Server(opts){
if (~this.transports.indexOf('websocket')) {
this.ws = new WebSocketServer({ noServer: true, clientTracking: false });
}
};
}
/**
* Protocol errors mappings.
@@ -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;
@@ -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){
self.onWebSocket(req, conn);
});
});