diff options
author | Vitaly Buka <vitalybuka@google.com> | 2018-05-08 18:32:53 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2018-05-08 18:32:53 +0000 |
commit | 6d2f5b966ec2b0bf44bd9a8c5afd1528a02810ca (patch) | |
tree | 606d25d7a9d23c48a4ba98b1919a4662bd390e74 /lib/sanitizer_common/sanitizer_file.cc | |
parent | 0bd8497bed74bb0c8acf54fae4b747f10041107b (diff) |
[sanitizer] Close fd on ReadFromFile error
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@331789 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_file.cc')
-rw-r--r-- | lib/sanitizer_common/sanitizer_file.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/sanitizer_common/sanitizer_file.cc b/lib/sanitizer_common/sanitizer_file.cc index a263a50cb..941d17a40 100644 --- a/lib/sanitizer_common/sanitizer_file.cc +++ b/lib/sanitizer_common/sanitizer_file.cc @@ -102,11 +102,12 @@ bool ReadFileToBuffer(const char *file_name, char **buff, uptr *buff_size, *read_len = 0; // The files we usually open are not seekable, so try different buffer sizes. for (uptr size = kMinFileLen; size <= max_len; size *= 2) { - fd_t fd = OpenFile(file_name, RdOnly, errno_p); - if (fd == kInvalidFd) return false; UnmapOrDie(*buff, *buff_size); *buff = (char*)MmapOrDie(size, __func__); *buff_size = size; + fd_t fd = OpenFile(file_name, RdOnly, errno_p); + if (fd == kInvalidFd) + return false; *read_len = 0; // Read up to one page at a time. bool reached_eof = false; @@ -114,6 +115,7 @@ bool ReadFileToBuffer(const char *file_name, char **buff, uptr *buff_size, uptr just_read; if (!ReadFromFile(fd, *buff + *read_len, PageSize, &just_read, errno_p)) { UnmapOrDie(*buff, *buff_size); + CloseFile(fd); return false; } if (just_read == 0) { |