Skip to content

Commit

Permalink
fs: close file if fstat() fails in readFile()
Browse files Browse the repository at this point in the history
Currently, if fstat() fails in readFile(), the callback
is invoked without closing the file. This commit closes
the file before calling back.

Closes nodejs#7697
  • Loading branch information
cjihrig authored and piscisaureus committed May 29, 2014
1 parent 57c5655 commit c7b0203
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ fs.readFile = function(path, options, callback_) {
fd = fd_;

fs.fstat(fd, function(er, st) {
if (er) return callback(er);
if (er) {
return fs.close(fd, function() {
callback(er);
});
}

size = st.size;
if (size === 0) {
// the kernel lies about many files.
Expand Down

0 comments on commit c7b0203

Please sign in to comment.