Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4b10580 authored by Billy Lau's avatar Billy Lau
Browse files

PackageUtils: Use try-with block for DigestInputStream.

Bug: 332045106

Previously, a DigestInputStream object was opened within an
ordinary try clause that was not explicitly closed, causing
potential resource leakage.

This fix changes the opening of that to be within a try-with
clause to ensure auto closure of the stream.

Test: Manual.
      adb shell cmd transparency get apex_info -o
      The command above was executed pre and post change to
      ensure SHA256 of large files are still computed correctly
      by this change.
Change-Id: Ic56dbf72ae8375e9f6897eea93f56a6148e33bc1
parent ac18d855
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -203,9 +203,8 @@ public final class PackageUtils {
        }

        File f = new File(filePath);
        try {
            DigestInputStream digestInputStream = new DigestInputStream(new FileInputStream(f),
                    messageDigest);
        try (DigestInputStream digestInputStream = new DigestInputStream(new FileInputStream(f),
                messageDigest)) {
            while (digestInputStream.read(fileBuffer) != -1);
        } catch (IOException e) {
            e.printStackTrace();