summaryrefslogtreecommitdiff
path: root/lib
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
parentc862c0348530824bfacef8eadfaf448120d91664 (diff)
downloadandroid-node-v8-72cc66e5033ea8900582da5a19b4032d8120e24c.tar.gz
android-node-v8-72cc66e5033ea8900582da5a19b4032d8120e24c.tar.bz2
android-node-v8-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')
-rw-r--r--lib/fs.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/fs.js b/lib/fs.js
index b7d47ed3a4..8f95d624ae 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.