Skip to content

Commit

Permalink
Close HttpUrlConnections when following redirects in HttpUrlFetcher.
Browse files Browse the repository at this point in the history
Progress towards #2352.
  • Loading branch information
sjudd committed Sep 7, 2017
1 parent 8cbfc63 commit 7f62597
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ private InputStream loadDataWithRedirects(URL url, int redirects, URL lastUrl,
throw new HttpException("Received empty or null redirect url");
}
URL redirectUrl = new URL(url, redirectUrlString);
// Closing the stream specifically is required to avoid leaking ResponseBodys in addition
// to disconnecting the url connection below. See #2352.
urlConnection.getInputStream().close();
urlConnection.disconnect();
urlConnection = null;
return loadDataWithRedirects(redirectUrl, redirects + 1, url, headers);
} else if (statusCode == -1) {
throw new HttpException(statusCode);
Expand Down

0 comments on commit 7f62597

Please sign in to comment.