diff options
author | David 'Digit' Turner <digit+github@google.com> | 2022-02-18 14:00:07 (GMT) |
---|---|---|
committer | David 'Digit' Turner <digit+github@google.com> | 2022-02-18 14:01:08 (GMT) |
commit | 9116613e39ba4e18f50494e97eb968a874effdcf (patch) | |
tree | e89406664a3d9d20b01a9cef4333e102ce106898 /src/util.cc | |
parent | f404f0059d71c8c86da7b56c48794266b5befd10 (diff) | |
download | Ninja-9116613e39ba4e18f50494e97eb968a874effdcf.zip Ninja-9116613e39ba4e18f50494e97eb968a874effdcf.tar.gz Ninja-9116613e39ba4e18f50494e97eb968a874effdcf.tar.bz2 |
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.
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 3 |
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; |