Skip to content

Commit

Permalink
Merge pull request #608 from darrachequesne/master
Browse files Browse the repository at this point in the history
Release memory used by PerMessageDeflate extension
  • Loading branch information
3rd-Eden committed Nov 26, 2015
2 parents 7debd82 + 718ac22 commit 6e4ccca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/PerMessageDeflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ PerMessageDeflate.prototype.accept = function(paramsList) {
return params;
};

/**
* Releases all resources used by the extension
*
* @api public
*/

PerMessageDeflate.prototype.cleanup = function() {
if (this._inflate) {
this._inflate.close();
this._inflate = null;
}
if (this._deflate) {
this._deflate.close();
this._deflate = null;
}
};

/**
* Accept extension offer from client
*
Expand Down Expand Up @@ -231,9 +248,11 @@ PerMessageDeflate.prototype.decompress = function (data, fin, callback) {
}

function cleanup() {
if (!self._inflate) return;
self._inflate.removeListener('error', onError);
self._inflate.removeListener('data', onData);
if (fin && self.params[endpoint + '_no_context_takeover']) {
self._inflate.close();
self._inflate = null;
}
}
Expand Down Expand Up @@ -281,9 +300,11 @@ PerMessageDeflate.prototype.compress = function (data, fin, callback) {
}

function cleanup() {
if (!self._deflate) return;
self._deflate.removeListener('error', onError);
self._deflate.removeListener('data', onData);
if (fin && self.params[endpoint + '_no_context_takeover']) {
self._deflate.close();
self._deflate = null;
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,12 @@ function cleanupWebsocketResources(error) {
this._receiver = null;
}

if (this.extensions[PerMessageDeflate.extensionName]) {
this.extensions[PerMessageDeflate.extensionName].cleanup();
}

this.extensions = null;

this.removeAllListeners();
this.on('error', function onerror() {}); // catch all errors after this
delete this._queue;
Expand Down

0 comments on commit 6e4ccca

Please sign in to comment.