KNOX-1430 - Potential output stream handle leak when copyLarge files in streamRespons...
authorLarry McCay <larry.mccay@oracle.com>
Thu, 30 Aug 2018 22:45:20 +0000 (18:45 -0400)
committerLarry McCay <larry.mccay@oracle.com>
Thu, 30 Aug 2018 22:45:20 +0000 (18:45 -0400)
gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteResponse.java

index d451c26..d623079 100644 (file)
@@ -181,9 +181,12 @@ public class UrlRewriteResponse extends GatewayResponseWrapper implements Params
     InputStream filteredInput = UrlRewriteStreamFilterFactory.create(
         mimeType, null, inStream, rewriter, this, UrlRewriter.Direction.OUT, filterContentConfig );
     outStream = (isGzip) ? new GZIPOutputStream(output) : output;
-    IOUtils.copyLarge( filteredInput, outStream, new byte[STREAM_BUFFER_SIZE] );
-    //KNOX-685: outStream.flush();
-    outStream.close();
+    try {
+        IOUtils.copyLarge( filteredInput, outStream, new byte[STREAM_BUFFER_SIZE] );
+    } finally {
+        //KNOX-685: outStream.flush();
+        outStream.close();
+    }
   }
 
   //TODO: Need to buffer the output here and when it is closed, rewrite it and then write the result to the stream.