From ddbf5a12896aff4164366c6d062607a925bde224 Mon Sep 17 00:00:00 2001 From: PioLing <964472638@qq.com> Date: Wed, 17 Jan 2024 17:18:11 +0800 Subject: [PATCH] Add error handling for the MapViewOfFile() function --- src/Http/HttpBody.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Http/HttpBody.cpp b/src/Http/HttpBody.cpp index d6eda3dd..4a18ffd1 100644 --- a/src/Http/HttpBody.cpp +++ b/src/Http/HttpBody.cpp @@ -153,6 +153,11 @@ static std::shared_ptr 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 ret((char *)(addr_), [hfile, hmapping, fp, file_path](char *addr_) { mmap_close(hfile, hmapping, addr_); delSharedMmap(file_path, addr_);