Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Filehandle leak on error #157

Merged
merged 2 commits into from

2 participants

@felixge

Why? That's implicit in JS, no?

"function has inconsistent return points" was the warning

Owner

"I don't give a shit" would be my reply : p. (I see the point, I just don't agree with it).

That's cool. I'll just do the line 14 fix and remove the rest from the Pull if you want.

@felixge

I like my trailing commas. They make it easier to edit and re-arrange things later.

I like warning-free code. Feel free to put them back, I don't really mind - and it's my fault anyway for using a strict IDE.

Owner

I also like warning free code. But I don't agree with the rules JSLint tries to enforce.

Either way, I merged it as I'd rather have the rest of your improvements (like the missing semicolons) as quick as possible : ).

@felixge felixge merged commit a3d7402 into from
@felixge
Owner

Thanks, commented on the lint stuff - but pulled it in anyway. But keep in mind if you send me patches again.

@OrangeDog

This needs another fix, but I can't work out how to do a pull request for just a single commit.
85e4209

@felixge
Owner

@OrangeDog I was about to pull this in, but noticed a failing test probably related to your previous pull:

  /Users/felix/code/node-formidable/lib/incoming_form.js:259
    this.openedFiles.forEach(function(file) {
                     ^
  TypeError: Cannot call method 'forEach' of undefined
      at IncomingForm._error (/Users/felix/code/node-formidable/lib/incoming_form.js:259:20)
      at _error (/Users/felix/code/node-formidable/test/legacy/simple/test-incoming-form.js:553:8)
      at test (/Users/felix/code/node-formidable/test/legacy/simple/test-incoming-form.js:22:3)
      at Object.<anonymous> (/Users/felix/code/node-formidable/test/legacy/simple/test-incoming-form.js:544:1)
      at Module._compile (module.js:449:26)
      at Object.Module._extensions..js (module.js:467:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:312:12)
      at Module.runMain (module.js:487:10)
      at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Could you have a look? Then I'll pull the other patch and release a new npm version.

@OrangeDog

Yep, that is what 85e4209 should fix.

The other submit on my branch is for #66, did you want me to sort out tests for that first or are you happy to take that for the next release as is?

@felixge
Owner

Yep, that is what 85e4209 should fix.

Nope, test still fails for me, even with that patch applied.

The other submit on my branch is for #66, did you want me to sort out tests for that first or are you happy to take that for the next release as is?

Seems like you closed #66, not sure what to do with it.

@OrangeDog

Nope, test still fails for me, even with that patch applied.

OK, see 258ed6a7cd3d25760b344c12836d47be897fde36.

Seems like you closed #66, not sure what to do with it.

No, it just got referenced from this "closed" pull request, but the issue is still open.
If you can give me a clue on how to do a pull request for only a subset of commits, I'll sort it out.

@OrangeDog

Scrap the commit in the middle - there's still a race condition in there where it will throw.

@felixge
Owner

Scrap the commit in the middle - there's still a race condition in there where it will throw.

Do you have a patch for this?

@OrangeDog

Scrap the commit in the middle - there's still a race condition in there where it will throw.

Do you have a patch for this?

No. Will do a separate pull request for that whole thing once it's sorted.

@felixge
Owner

Sweet, thanks!

@OrangeDog

To clarify, by "that whole thing" I mean #66, not the extra fixes to #157.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 13, 2012
  1. @OrangeDog

    de-linting

    OrangeDog authored
  2. @OrangeDog
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 7 deletions.
  1. +11 −3 lib/incoming_form.js
  2. +4 −4 lib/multipart_parser.js
View
14 lib/incoming_form.js
@@ -11,7 +11,7 @@ var util = require('./util'),
Stream = require('stream').Stream;
function IncomingForm(opts) {
- if (!(this instanceof IncomingForm)) return new IncomingForm;
+ if (!(this instanceof IncomingForm)) return new IncomingForm(opts);
EventEmitter.call(this);
opts=opts||{};
@@ -33,6 +33,7 @@ function IncomingForm(opts) {
this._parser = null;
this._flushing = 0;
this._fieldsSize = 0;
+ return this;
};
util.inherits(IncomingForm, EventEmitter);
exports.IncomingForm = IncomingForm;
@@ -88,6 +89,7 @@ IncomingForm.prototype.parse = function(req, cb) {
};
this.writeHeaders(req.headers);
+ this.openedFiles = [];
var self = this;
req
@@ -203,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();
@@ -252,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() {
@@ -336,7 +344,7 @@ IncomingForm.prototype._initMultipart = function(boundary) {
};
IncomingForm.prototype._fileName = function(headerValue) {
- var m = headerValue.match(/filename="(.*?)"($|; )/i)
+ var m = headerValue.match(/filename="(.*?)"($|; )/i);
if (!m) return;
var filename = m[1].substr(m[1].lastIndexOf('\\') + 1);
@@ -373,7 +381,7 @@ IncomingForm.prototype._uploadPath = function(filename) {
if (this.keepExtensions) {
var ext = path.extname(filename);
- ext = ext.replace(/(\.[a-z0-9]+).*/, '$1')
+ ext = ext.replace(/(\.[a-z0-9]+).*/, '$1');
name += ext;
}
View
8 lib/multipart_parser.js
@@ -13,13 +13,13 @@ var Buffer = require('buffer').Buffer,
PART_DATA_START: s++,
PART_DATA: s++,
PART_END: s++,
- END: s++,
+ END: s++
},
f = 1,
F =
{ PART_BOUNDARY: f,
- LAST_BOUNDARY: f *= 2,
+ LAST_BOUNDARY: f *= 2
},
LF = 10,
@@ -34,7 +34,7 @@ var Buffer = require('buffer').Buffer,
return c | 0x20;
};
-for (var s in S) {
+for (s in S) {
exports[s] = S[s];
}
@@ -207,7 +207,7 @@ MultipartParser.prototype.write = function(buffer) {
state = S.PART_DATA_START;
break;
case S.PART_DATA_START:
- state = S.PART_DATA
+ state = S.PART_DATA;
mark('partData');
case S.PART_DATA:
prevIndex = index;
Something went wrong with that request. Please try again.