summaryrefslogtreecommitdiff
path: root/lib/fs.js
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:32 -0700
commit72cc66e5033ea8900582da5a19b4032d8120e24c (patch)
treebe59c96340127e4b8610cef1fff344e4d09af27d /lib/fs.js
parentc862c0348530824bfacef8eadfaf448120d91664 (diff)
downloadnodejs-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.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/fs.js b/lib/fs.js
index b7d47ed3a..8f95d624a 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -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.