Add error handling for the MapViewOfFile() function

This commit is contained in:
PioLing 2024-01-17 17:18:11 +08:00 committed by GitHub
parent 7f16d85906
commit ddbf5a1289
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View File

@ -153,6 +153,11 @@ static std::shared_ptr<char> getSharedMmap(const string &file_path, int64_t &fil
auto addr_ = ::MapViewOfFile(hmapping, FILE_MAP_READ, 0, 0, 0);
if (addr_ == nullptr) {
mmap_close(hfile, hmapping, addr_);
return nullptr;
}
std::shared_ptr<char> ret((char *)(addr_), [hfile, hmapping, fp, file_path](char *addr_) {
mmap_close(hfile, hmapping, addr_);
delSharedMmap(file_path, addr_);