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
This commit is contained in:
cjihrig 2014-05-28 18:34:04 -04:00 committed by Bert Belder
parent c862c03485
commit 72cc66e503

View File

@ -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.