Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add try/finally blocks to FILE.copy to prevent fd leaks on exceptions

  • Loading branch information...
commit d6d9bde63f42dea6a3df1be7f65c23bdede99ff9 1 parent 14d938d
Paul Baumgart paulbaumgart authored
Showing with 11 additions and 3 deletions.
  1. +11 −3 lib/file.js
14 lib/file.js
View
@@ -196,9 +196,17 @@ exports.write = function (path, data, options) {
exports.copy = function (source, target) {
source = exports.path(source);
target = exports.path(target);
- var targetStream = target.open("wb");
- source.open("rb").copy(targetStream).close();
- targetStream.close();
+ var sourceStream = source.open("rb");
+ try {
+ var targetStream = target.open("wb");
+ try {
+ sourceStream.copy(targetStream);
+ } finally {
+ targetStream.close();
+ }
+ } finally {
+ sourceStream.close();
+ }
};
var list = exports.list;
Please sign in to comment.
Something went wrong with that request. Please try again.