Always close the GZIPOutputStream to release Deflater

The stream must be closed to ensure the native resources associated
with its internal Deflater instance are cleaned up early, instead of
waiting for GC to identify the dead object and finialize it.

Change-Id: Ic31b5df563f19404ed4682556999f4332aa61562
This commit is contained in:
Shawn O. Pearce 2011-11-30 17:17:59 -08:00
parent cea935ab1b
commit 0d61707f12
1 changed files with 5 additions and 2 deletions

View File

@ -101,8 +101,11 @@ public void close() throws IOException {
TemporaryBuffer gzbuf = new TemporaryBuffer.Heap(LIMIT);
try {
GZIPOutputStream gzip = new GZIPOutputStream(gzbuf);
out.writeTo(gzip, null);
gzip.close();
try {
out.writeTo(gzip, null);
} finally {
gzip.close();
}
if (gzbuf.length() < out.length()) {
out = gzbuf;
rsp.setHeader(HDR_CONTENT_ENCODING, ENCODING_GZIP);