[sanitizer] Close fd on ReadFromFile error

llvm-svn: 331789
This commit is contained in:
Vitaly Buka 2018-05-08 18:32:53 +00:00
parent d049da3740
commit 6b13684d15
1 changed files with 4 additions and 2 deletions

View File

@ -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) {