]> source.dussan.org Git - jgit.git/commitdiff
Always close the GZIPOutputStream to release Deflater 14/4714/1
authorShawn O. Pearce <spearce@spearce.org>
Thu, 1 Dec 2011 01:17:59 +0000 (17:17 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Thu, 1 Dec 2011 01:45:41 +0000 (17:45 -0800)
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

org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartOutputStream.java

index 00cb67ca9593bc922e96610d2d6ec831eebb6ccb..c39b78900debb00af0adbdb4d4eda049100130b0 100644 (file)
@@ -101,8 +101,11 @@ class SmartOutputStream extends TemporaryBuffer {
                                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);