From 529b24064c90134d85cfa15f597e929ca8aac266 Mon Sep 17 00:00:00 2001 From: Matthias Krueger Date: Mon, 1 Aug 2022 20:17:45 +0200 Subject: [PATCH] Explicitly call Deflater/Inflater#close to free native resources (#203) (#204) --- .../common/GlueSchemaRegistryCompressionHandler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/amazonaws/services/schemaregistry/common/GlueSchemaRegistryCompressionHandler.java b/common/src/main/java/com/amazonaws/services/schemaregistry/common/GlueSchemaRegistryCompressionHandler.java index cc221957..df84b55f 100644 --- a/common/src/main/java/com/amazonaws/services/schemaregistry/common/GlueSchemaRegistryCompressionHandler.java +++ b/common/src/main/java/com/amazonaws/services/schemaregistry/common/GlueSchemaRegistryCompressionHandler.java @@ -81,7 +81,10 @@ static byte[] writeToByteArrayOutputStream(Inflater inflater, ByteArrayOutputStr * @throws IOException */ default byte[] compress(byte[] record) throws IOException { - return writeToDeflatorObject(record, getDeflatorObject(record)); + Deflater deflator = getDeflatorObject(record); + byte[] compressed = writeToDeflatorObject(record, deflator); + deflator.end(); + return compressed; } /** @@ -95,6 +98,9 @@ default byte[] compress(byte[] record) throws IOException { * @throws IOException */ default byte[] decompress(byte[] compressedRecord, int start, int end) throws IOException { - return decompress(getInflatorObject(compressedRecord, start, end), compressedRecord.length); + Inflater inflator = getInflatorObject(compressedRecord, start, end); + byte[] decompressed = decompress(inflator, compressedRecord.length); + inflator.end(); + return decompressed; } }