Fixed: Resource leakage inside ManagedHttpDispatcher.

Leonardo Galli 6 years ago
parent 42015d5d95
commit eb077b043e

@ -20,7 +20,11 @@ namespace NzbDrone.Common.Http.Dispatchers
public HttpResponse GetResponse(HttpRequest request, CookieContainer cookies)
{
var webRequest = (HttpWebRequest)WebRequest.Create((Uri)request.Url);
HttpWebResponse httpWebResponse = null;
HttpWebRequest webRequest = null;
try
{
webRequest = (HttpWebRequest) WebRequest.Create((Uri) request.Url);
// Deflate is not a standard and could break depending on implementation.
// we should just stick with the more compatible Gzip
@ -28,7 +32,9 @@ namespace NzbDrone.Common.Http.Dispatchers
webRequest.AutomaticDecompression = DecompressionMethods.GZip;
webRequest.Method = request.Method.ToString();
webRequest.UserAgent = request.UseSimplifiedUserAgent ? UserAgentBuilder.UserAgentSimplified : UserAgentBuilder.UserAgent;
webRequest.UserAgent = request.UseSimplifiedUserAgent
? UserAgentBuilder.UserAgentSimplified
: UserAgentBuilder.UserAgent;
webRequest.KeepAlive = request.ConnectionKeepAlive;
webRequest.AllowAutoRedirect = false;
webRequest.CookieContainer = cookies;
@ -54,8 +60,6 @@ namespace NzbDrone.Common.Http.Dispatchers
}
}
HttpWebResponse httpWebResponse;
try
{
httpWebResponse = (HttpWebResponse) webRequest.GetResponse();
@ -85,7 +89,15 @@ namespace NzbDrone.Common.Http.Dispatchers
}
}
return new HttpResponse(request, new HttpHeader(httpWebResponse.Headers), data, httpWebResponse.StatusCode);
return new HttpResponse(request, new HttpHeader(httpWebResponse.Headers), data,
httpWebResponse.StatusCode);
}
finally
{
webRequest = null;
httpWebResponse?.Dispose();
httpWebResponse = null;
}
}
protected virtual void AddProxy(HttpWebRequest webRequest, HttpRequest request)

Loading…
Cancel
Save