Fix leaking okhttp response in error case.

Closes #13246
This commit is contained in:
AsamK
2023-11-09 10:11:53 +01:00
committed by Cody Henthorne
parent d2053d2db7
commit 43a13964bd

View File

@@ -1960,9 +1960,17 @@ public class PushServiceSocket {
boolean doNotAddAuthenticationOrUnidentifiedAccessKey)
throws NonSuccessfulResponseCodeException, PushNetworkException, MalformedResponseException
{
Response response = getServiceConnection(urlFragment, method, body, headers, unidentifiedAccessKey, doNotAddAuthenticationOrUnidentifiedAccessKey);
responseCodeHandler.handle(response.code(), response.body());
return validateServiceResponse(response);
Response response = null;
try {
response = getServiceConnection(urlFragment, method, body, headers, unidentifiedAccessKey, doNotAddAuthenticationOrUnidentifiedAccessKey);
responseCodeHandler.handle(response.code(), response.body());
return validateServiceResponse(response);
} catch (Exception e) {
if (response != null && response.body() != null) {
response.body().close();
}
throw e;
}
}
private Response validateServiceResponse(Response response)