From c7b02034ef80313564c50c59c63a5b640c24e234 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 28 May 2014 18:34:04 -0400 Subject: [PATCH] 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 --- lib/fs.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index cdcc13d329..e8e8250350 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -229,7 +229,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.