diff options
author | cjihrig <cjihrig@gmail.com> | 2014-05-28 18:34:04 -0400 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2014-05-28 18:58:57 -0700 |
commit | b93a51e3a61be44db3e566d3b4bf8b6d2c28db6f (patch) | |
tree | 8b5b840ba65d527e5ae9c85f0687aaf98f9125b9 | |
parent | 10b6156bd2f586bd7bd145f61274d18d2f5c2376 (diff) | |
download | node-b93a51e3a61be44db3e566d3b4bf8b6d2c28db6f.tar.gz |
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
-rw-r--r-- | lib/fs.js | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -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. |