From 6c6f058a8ce3d6e6b6eb255f4004ead2c48989d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sun, 4 Feb 2024 16:23:35 +0100 Subject: [PATCH] Cleanup HTTP request cleanup Ensure with assertion that file is closed when `CHttpRequest` is destructed. Remove unnecessary assignments in destructor. --- src/engine/shared/http.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/engine/shared/http.cpp b/src/engine/shared/http.cpp index 771cf2052..4e6ac6bdc 100644 --- a/src/engine/shared/http.cpp +++ b/src/engine/shared/http.cpp @@ -72,21 +72,10 @@ CHttpRequest::CHttpRequest(const char *pUrl) CHttpRequest::~CHttpRequest() { - m_ResponseLength = 0; - if(!m_WriteToFile) - { - m_BufferSize = 0; - free(m_pBuffer); - m_pBuffer = nullptr; - } + dbg_assert(m_File == nullptr, "HTTP request file was not closed"); + free(m_pBuffer); curl_slist_free_all((curl_slist *)m_pHeaders); - m_pHeaders = nullptr; - if(m_pBody) - { - m_BodyLength = 0; - free(m_pBody); - m_pBody = nullptr; - } + free(m_pBody); } bool CHttpRequest::BeforeInit() @@ -317,6 +306,7 @@ void CHttpRequest::OnCompletionInternal(std::optional Result) dbg_msg("http", "i/o error, cannot close file: %s", m_aDest); State = EHttpState::ERROR; } + m_File = nullptr; if(State == EHttpState::ERROR || State == EHttpState::ABORTED) {