diff --git a/lib/fs.js b/lib/fs.js index 5bbcf057cd4..52157e8db3e 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.