Skip to content

Commit 97ad067

Browse files
authored
Merge pull request microsoft#495 from vadz/proxy-info-memleak
Fix memory leak of WINHTTP_PROXY_INFO fields
2 parents 64dd067 + 7b47d0c commit 97ad067

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Release/src/http/client/http_client_winhttp.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,24 @@ static DWORD ChooseAuthScheme( DWORD dwSupportedSchemes )
297297
return 0;
298298
}
299299

300+
// Small RAII helper to ensure that the fields of this struct are always
301+
// properly freed.
302+
struct proxy_info : WINHTTP_PROXY_INFO
303+
{
304+
proxy_info()
305+
{
306+
memset( this, 0, sizeof(WINHTTP_PROXY_INFO) );
307+
}
308+
309+
~proxy_info()
310+
{
311+
if ( lpszProxy )
312+
::GlobalFree(lpszProxy);
313+
if ( lpszProxyBypass )
314+
::GlobalFree(lpszProxyBypass);
315+
}
316+
};
317+
300318
// WinHTTP client.
301319
class winhttp_client : public _http_client_communicator
302320
{
@@ -494,14 +512,13 @@ class winhttp_client : public _http_client_communicator
494512
http_request &msg = request->m_request;
495513
winhttp_request_context * winhttp_context = static_cast<winhttp_request_context *>(request.get());
496514

497-
WINHTTP_PROXY_INFO info;
515+
proxy_info info;
498516
bool proxy_info_required = false;
499517

500518
if( client_config().proxy().is_auto_discovery() )
501519
{
502520
WINHTTP_AUTOPROXY_OPTIONS autoproxy_options;
503521
memset( &autoproxy_options, 0, sizeof(WINHTTP_AUTOPROXY_OPTIONS) );
504-
memset( &info, 0, sizeof(WINHTTP_PROXY_INFO) );
505522

506523
autoproxy_options.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
507524
autoproxy_options.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP | WINHTTP_AUTO_DETECT_TYPE_DNS_A;

0 commit comments

Comments
 (0)