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:32 -0700 |
commit | 72cc66e5033ea8900582da5a19b4032d8120e24c (patch) | |
tree | be59c96340127e4b8610cef1fff344e4d09af27d /lib/fs.js | |
parent | c862c0348530824bfacef8eadfaf448120d91664 (diff) | |
download | nodejs-72cc66e5033ea8900582da5a19b4032d8120e24c.tar.gz nodejs-72cc66e5033ea8900582da5a19b4032d8120e24c.tar.bz2 nodejs-72cc66e5033ea8900582da5a19b4032d8120e24c.zip |
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
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 7 |
1 files changed, 6 insertions, 1 deletions
@@ -208,7 +208,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. |