Skip to content

Commit e3b6fda

Browse files
committed
Fix inflater leak #14
1 parent a85b380 commit e3b6fda

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

glideplugin/src/main/java/com/opensource/svgaplayer/glideplugin/SVGAEntityStreamDecoder.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.opensource.svgaplayer.proto.MovieEntity
88
import java.io.ByteArrayOutputStream
99
import java.io.File
1010
import java.io.InputStream
11+
import java.util.zip.Inflater
1112
import java.util.zip.InflaterInputStream
1213

1314
/**
@@ -35,8 +36,9 @@ internal class SVGAEntityStreamDecoder(
3536

3637
private fun inflate(source: InputStream): ByteArray? = attempt {
3738
val buffer = arrayPool.get(ArrayPool.STANDARD_BUFFER_SIZE_BYTES, ByteArray::class.java)
39+
val inflater = Inflater()
3840
try {
39-
InflaterInputStream(source).let { input ->
41+
InflaterInputStream(source, inflater).let { input ->
4042
ByteArrayOutputStream().let { output ->
4143
while (true) {
4244
val cnt = input.read(buffer)
@@ -48,6 +50,7 @@ internal class SVGAEntityStreamDecoder(
4850
}
4951
} finally {
5052
arrayPool.put(buffer)
53+
inflater.end()
5154
}
5255
}
5356
}

0 commit comments

Comments
 (0)