Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

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 #7697
  • Loading branch information
cjihrig authored and piscisaureus committed May 29, 2014
1 parent 10b6156 commit b93a51e
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 @@ -118,7 +118,12 @@ fs.readFile = function(path, encoding_) {
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 b93a51e

Please sign in to comment.