Skip to content

Commit

Permalink
Fix leaking okhttp response in error case.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK authored and TwoLeaves committed Feb 7, 2024
1 parent de0f473 commit 89ca705
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1960,9 +1960,17 @@ private Response makeServiceRequest(String urlFragment,
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)
Expand Down

0 comments on commit 89ca705

Please sign in to comment.