From 1a595dd8fd3ad59d6a6fd05499d5ad7cf95a2a66 Mon Sep 17 00:00:00 2001 From: Javac Team Date: Tue, 12 Nov 2024 16:43:31 -0800 Subject: [PATCH] Promptly end() the Inflater in Turbine. This will more-eagerly release memory allocated via JNI calls to zlib. See the API note on the Inflater javadoc: "To release resources used by this Inflater, the end() method should be called explicitly. Subclasses are responsible for the cleanup of resources acquired by the subclass." https://download.java.net/java/early_access/jdk24/docs/api/java.base/java/util/zip/Inflater.html PiperOrigin-RevId: 695914851 --- java/com/google/turbine/zip/Zip.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/java/com/google/turbine/zip/Zip.java b/java/com/google/turbine/zip/Zip.java index 95ebb3f..3698d59 100644 --- a/java/com/google/turbine/zip/Zip.java +++ b/java/com/google/turbine/zip/Zip.java @@ -342,10 +342,9 @@ private byte[] getBytes( byte[] bytes = new byte[(int) size]; fc.get(bytes); if (deflate) { - bytes = - new InflaterInputStream( - new ByteArrayInputStream(bytes), new Inflater(/* nowrap= */ true)) - .readAllBytes(); + Inflater inf = new Inflater(/* nowrap= */ true); + bytes = new InflaterInputStream(new ByteArrayInputStream(bytes), inf).readAllBytes(); + inf.end(); } return bytes; } catch (IOException e) {