runtime
runtime copied to clipboard
WinHttpRequestState memory leak when sending WinHttp requests from WinHttpHandler.
Noticed during code review that there is a potential memory leak in GCHandle and WinHttpRequestState instances when WinHttpHandler.InternalSendRequestAsync() executed repeatedly from asynchronous do/while loop in WinHttpHandler.StartRequest.
Cause:
WinHttpRequestState may pin WinHttpRequestState instances multiple times due to missing _operationHandle.IsAllocated check around _operationHandle = GCHandle.Alloc(this):
public void Pin()
{
#if DEBUG
Interlocked.Increment(ref s_dbg_pin);
#endif
_operationHandle = GCHandle.Alloc(this);
}
Maybe related to issue #11674
cc: @stephentoub
@baal2000 Thanks for finding that bug!
you are welcome.