HttpDiscovery: Fix resource leak as a result of unclosed GZIPInputStream.
@@ -98,8 +98,13 @@ public class HttpDiscovery implements PeerDiscovery {
throw new PeerDiscoveryException("HTTP request failed: " + response.code() + " " + response.message());
InputStream stream = response.body().byteStream();
GZIPInputStream zip = new GZIPInputStream(stream);
- PeerSeedProtos.SignedPeerSeeds proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
- stream.close();
+ PeerSeedProtos.SignedPeerSeeds proto;
+ try {
+ proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
+ } finally {
+ zip.close(); // will close InputStream as well
+ }
+
return protoToAddrs(proto);
} catch (PeerDiscoveryException e1) {
throw e1;
