HttpDiscovery: Fix resource leak as a result of unclosed GZIPInputStream.

This commit is contained in:
Bas van Schaik
2017-04-27 18:14:21 +01:00
committed by Andreas Schildbach
parent 5a08847e42
commit a20087eee3

View File

@@ -94,8 +94,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;