summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit+github@google.com>2022-02-18 15:00:07 +0100
committerDavid 'Digit' Turner <digit+github@google.com>2022-02-18 15:01:08 +0100
commit9116613e39ba4e18f50494e97eb968a874effdcf (patch)
treee89406664a3d9d20b01a9cef4333e102ce106898
parentf404f0059d71c8c86da7b56c48794266b5befd10 (diff)
downloadninja-9116613e39ba4e18f50494e97eb968a874effdcf.tar.gz
Fix ReadFile() handle leak on read error on Windows.
Small change to fix a file handle leak in case of error. Also return -EIO instead of -1 to signal read errors, since it is more consistent with what is happening here.
-rw-r--r--src/util.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/util.cc b/src/util.cc
index 080883e..a2a0f27 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -350,7 +350,8 @@ int ReadFile(const string& path, string* contents, string* err) {
if (!::ReadFile(f, buf, sizeof(buf), &len, NULL)) {
err->assign(GetLastErrorString());
contents->clear();
- return -1;
+ ::CloseHandle(f);
+ return -EIO;
}
if (len == 0)
break;