Permalink
Browse files

clean-up open filehandles and files on error

  • Loading branch information...
1 parent 31c2c3f commit 56655355a47f06ff002de5c143e6cda1a40a6a98 @OrangeDog OrangeDog committed Jul 13, 2012
Showing with 7 additions and 0 deletions.
  1. +7 −0 lib/incoming_form.js
View
@@ -89,6 +89,7 @@ IncomingForm.prototype.parse = function(req, cb) {
};
this.writeHeaders(req.headers);
+ this.openedFiles = [];
var self = this;
req
@@ -204,6 +205,7 @@ IncomingForm.prototype.handlePart = function(part) {
this.emit('fileBegin', part.name, file);
file.open();
+ this.openedFiles.push(file);
part.on('data', function(buffer) {
self.pause();
@@ -253,6 +255,11 @@ IncomingForm.prototype._error = function(err) {
this.error = err;
this.pause();
this.emit('error', err);
+
+ this.openedFiles.forEach(function(file) {
+ file._writeStream.destroy();
+ setTimeout(fs.unlink, 0, file.path);
+ });
};
IncomingForm.prototype._parseContentLength = function() {

0 comments on commit 5665535

Please sign in to comment.