Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CID-156932] - Fix the imaginary resource leak in NullOutputStream #172

Merged
merged 2 commits into from
Jun 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/java/hudson/remoting/Checksum.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.security.DigestOutputStream;
Expand Down Expand Up @@ -74,8 +75,10 @@ static Checksum forFile(File file) throws IOException {
static Checksum forURL(URL url) throws IOException {
try {
MessageDigest md = MessageDigest.getInstance(JarLoaderImpl.DIGEST_ALGORITHM);
Util.copy(url.openStream(), new DigestOutputStream(new NullOutputStream(), md));
return new Checksum(md.digest(), md.getDigestLength() / 8);
try(InputStream istsream = url.openStream(); OutputStream ostream = new DigestOutputStream(new NullOutputStream(), md)) {
Util.copy(istsream, ostream);
return new Checksum(md.digest(), md.getDigestLength() / 8);
}
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
Expand Down