Browse Source

fs: close file if fstat() fails in readFile()

Currently, if fstat() fails in readFile(), the callback
is invoked without closing the file. This commit closes
the file before calling back.

Closes #7697
archived-io.js-v0.10
cjihrig 11 years ago
committed by Bert Belder
parent
commit
c7b02034ef
  1. 7
      lib/fs.js

7
lib/fs.js

@ -229,7 +229,12 @@ fs.readFile = function(path, options, callback_) {
fd = fd_; fd = fd_;
fs.fstat(fd, function(er, st) { fs.fstat(fd, function(er, st) {
if (er) return callback(er); if (er) {
return fs.close(fd, function() {
callback(er);
});
}
size = st.size; size = st.size;
if (size === 0) { if (size === 0) {
// the kernel lies about many files. // the kernel lies about many files.

Loading…
Cancel
Save