[compiler-rt] r331789 - [sanitizer] Close fd on ReadFromFile error
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Tue May 8 11:32:54 PDT 2018
Author: vitalybuka
Date: Tue May 8 11:32:53 2018
New Revision: 331789
URL: http://llvm.org/viewvc/llvm-project?rev=331789&view=rev
Log:
[sanitizer] Close fd on ReadFromFile error
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc?rev=331789&r1=331788&r2=331789&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_file.cc Tue May 8 11:32:53 2018
@@ -102,11 +102,12 @@ bool ReadFileToBuffer(const char *file_n
*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_n
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) {
More information about the llvm-commits
mailing list