From b428e531eefe8e9f103406120e3c3366fb190fee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 16 Jan 2021 13:47:58 +0100 Subject: [PATCH] Check for errors when calling WinHttpCloseHandle() Add a trivial wxWinHTTPCloseHandle() wrapper calling wxLogLastError() if closing the handle failed -- this is really not expected to happen, so make sure to at least log it if it does. --- src/msw/webrequest_winhttp.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/msw/webrequest_winhttp.cpp b/src/msw/webrequest_winhttp.cpp index 716e9af7f9..102fc7305a 100644 --- a/src/msw/webrequest_winhttp.cpp +++ b/src/msw/webrequest_winhttp.cpp @@ -101,6 +101,15 @@ void wxWinHTTPSetOption(HINTERNET hInternet, DWORD dwOption, DWORD dwValue) ::WinHttpSetOption(hInternet, dwOption, &dwValue, sizeof(dwValue)); } +static +void wxWinHTTPCloseHandle(HINTERNET hInternet) +{ + if ( !::WinHttpCloseHandle(hInternet) ) + { + wxLogLastError("WinHttpCloseHandle"); + } +} + static void CALLBACK wxRequestStatusCallback( HINTERNET WXUNUSED(hInternet), DWORD_PTR dwContext, @@ -139,9 +148,9 @@ wxWebRequestWinHTTP::wxWebRequestWinHTTP(wxWebSession& session, wxWebRequestWinHTTP::~wxWebRequestWinHTTP() { if ( m_request ) - ::WinHttpCloseHandle(m_request); + wxWinHTTPCloseHandle(m_request); if ( m_connect ) - ::WinHttpCloseHandle(m_connect); + wxWinHTTPCloseHandle(m_connect); } void @@ -396,7 +405,7 @@ void wxWebRequestWinHTTP::Cancel() SetState(wxWebRequest::State_Cancelled); if ( m_request != NULL ) { - ::WinHttpCloseHandle(m_request); + wxWinHTTPCloseHandle(m_request); m_request = NULL; } } @@ -555,7 +564,7 @@ wxWebSessionWinHTTP::wxWebSessionWinHTTP(): wxWebSessionWinHTTP::~wxWebSessionWinHTTP() { if ( m_handle ) - ::WinHttpCloseHandle(m_handle); + wxWinHTTPCloseHandle(m_handle); } bool wxWebSessionWinHTTP::Open()