diff options
| author | Dan Engelbrecht <[email protected]> | 2023-09-12 08:03:46 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-12 14:03:46 +0200 |
| commit | f463686b9621b8c744e2dcb0d018ad507716d499 (patch) | |
| tree | 7cf50625dbfe3b731131b779c6286ae9ca6423d7 /src/zenhttp/httpclient.cpp | |
| parent | gracefully handle errors when writing cache log (#391) (diff) | |
| download | zen-f463686b9621b8c744e2dcb0d018ad507716d499.tar.xz zen-f463686b9621b8c744e2dcb0d018ad507716d499.zip | |
Make sure error logging or destructors don't throw exception when trying to get file name from handle (#393)
- Bugfix: Make sure error logging or destructors don't throw exception when trying to get file name from handle
Diffstat (limited to 'src/zenhttp/httpclient.cpp')
| -rw-r--r-- | src/zenhttp/httpclient.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/src/zenhttp/httpclient.cpp b/src/zenhttp/httpclient.cpp index b77b31933..5ae5f78d6 100644 --- a/src/zenhttp/httpclient.cpp +++ b/src/zenhttp/httpclient.cpp @@ -292,26 +292,33 @@ public: TempPayloadFile() : m_FileHandle(nullptr), m_WriteOffset(0) {} ~TempPayloadFile() { - if (m_FileHandle) + try { + if (m_FileHandle) + { #if ZEN_PLATFORM_WINDOWS - // Mark file for deletion when final handle is closed - FILE_DISPOSITION_INFO Fdi{.DeleteFile = TRUE}; + // Mark file for deletion when final handle is closed + FILE_DISPOSITION_INFO Fdi{.DeleteFile = TRUE}; - SetFileInformationByHandle(m_FileHandle, FileDispositionInfo, &Fdi, sizeof Fdi); - BOOL Success = CloseHandle(m_FileHandle); + SetFileInformationByHandle(m_FileHandle, FileDispositionInfo, &Fdi, sizeof Fdi); + BOOL Success = CloseHandle(m_FileHandle); #else - std::filesystem::path FilePath = zen::PathFromHandle(m_FileHandle); - unlink(FilePath.c_str()); - int Fd = int(uintptr_t(m_FileHandle)); - bool Success = (close(Fd) == 0); + std::filesystem::path FilePath = zen::PathFromHandle(m_FileHandle); + unlink(FilePath.c_str()); + int Fd = int(uintptr_t(m_FileHandle)); + bool Success = (close(Fd) == 0); #endif - if (!Success) - { - ZEN_WARN("Error reported on file handle close, reason '{}'", GetLastErrorAsString()); - } + if (!Success) + { + ZEN_WARN("Error reported on file handle close, reason '{}'", GetLastErrorAsString()); + } - m_FileHandle = nullptr; + m_FileHandle = nullptr; + } + } + catch (std::exception& Ex) + { + ZEN_ERROR("Failed deleting temp file {}. Reason '{}'", m_FileHandle, Ex.what()); } } |