summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2014-05-28 18:34:04 -0400
committerBert Belder <bertbelder@gmail.com>2014-05-28 18:58:57 -0700
commitb93a51e3a61be44db3e566d3b4bf8b6d2c28db6f (patch)
tree8b5b840ba65d527e5ae9c85f0687aaf98f9125b9
parent10b6156bd2f586bd7bd145f61274d18d2f5c2376 (diff)
downloadnode-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.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 5bbcf057c..52157e8db 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -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.