diff --git a/common/mapped-file-unix.cc b/common/mapped-file-unix.cc index c5d05526..918e6c5d 100644 --- a/common/mapped-file-unix.cc +++ b/common/mapped-file-unix.cc @@ -44,9 +44,8 @@ void MappedFile::close_fd() { } void MappedFile::reopen_fd(const std::string &path) { - if (fd != -1) - close(fd); - fd = open(path.c_str(), O_RDONLY); + if (fd == -1) + fd = open(path.c_str(), O_RDONLY); } } // namespace mold diff --git a/common/mapped-file-win32.cc b/common/mapped-file-win32.cc index e88af64b..93c3ef4b 100644 --- a/common/mapped-file-win32.cc +++ b/common/mapped-file-win32.cc @@ -72,11 +72,10 @@ void MappedFile::close_fd() { } void MappedFile::reopen_fd(const std::string &path) { - if (fd != INVALID_HANDLE_VALUE) - CloseHandle(fd); - fd = CreateFileA(path.c_str(), GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + if (fd == INVALID_HANDLE_VALUE) + fd = CreateFileA(path.c_str(), GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); } } // namespace mold