Permalink
Browse files

Merge pull request #1244 from RubenVerborgh/master

EventEmitter memory leak with successful sendfile
  • Loading branch information...
2 parents 07b6c9f + 8050308 commit cb844132e621a57f5855abab2bedb85bb3b0ddd6 @tj tj committed Jul 24, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/response.js
View
@@ -190,7 +190,7 @@ res.sendfile = function(path, options, fn){
done = true;
// clean up
- req.socket.removeListener('error', error);
+ cleanup();
if (!self.headerSent) self.removeHeader('Content-Disposition');
// callback available
@@ -206,10 +206,15 @@ res.sendfile = function(path, options, fn){
// streaming
function stream() {
if (done) return;
- req.socket.removeListener('error', error);
+ cleanup();
if (fn) self.on('finish', fn);
}
+ // cleanup
+ function cleanup() {
+ req.socket.removeListener('error', error);
+ }
+
// transfer
var file = send(req, path);
if (options.root) file.root(options.root);
@@ -218,6 +223,7 @@ res.sendfile = function(path, options, fn){
file.on('directory', next);
file.on('stream', stream);
file.pipe(this);
+ this.on('finish', cleanup);
};
/**

0 comments on commit cb84413

Please sign in to comment.