TEZ-3964. Inflater not closed in some places (Jaume M via jlowe)
authorJason Lowe <jlowe@apache.org>
Thu, 12 Jul 2018 15:48:07 +0000 (10:48 -0500)
committerJason Lowe <jlowe@apache.org>
Thu, 12 Jul 2018 15:48:07 +0000 (10:48 -0500)
tez-api/src/main/java/org/apache/tez/common/TezCommonUtils.java
tez-dag/src/main/java/org/apache/tez/dag/history/utils/DAGUtils.java

index c8e8e02..16165e2 100644 (file)
@@ -388,7 +388,12 @@ public class TezCommonUtils {
 
   @Private
   public static byte[] decompressByteStringToByteArray(ByteString byteString) throws IOException {
-    return decompressByteStringToByteArray(byteString, newInflater());
+    Inflater inflater = newInflater();
+    try {
+      return decompressByteStringToByteArray(byteString, inflater);
+    } finally {
+      inflater.end();
+    }
   }
 
   @Private
index b2622ad..77d3447 100644 (file)
@@ -139,7 +139,7 @@ public class DAGUtils {
   }
 
   public static Map<String,Object> convertCountersToATSMap(TezCounters counters) {
-    Map<String,Object> object = new LinkedHashMap<String, Object>();
+    Map<String, Object> object = new LinkedHashMap<String, Object>();
     if (counters == null) {
         return object;
       }
@@ -198,8 +198,24 @@ public class DAGUtils {
     return dagInfo;
   }
 
-  public static Map<String,Object> convertDAGPlanToATSMap(DAGPlan dagPlan) throws IOException {
+  public static Map<String, Object> convertDAGPlanToATSMap(final DAGPlan
+      dagPlan) throws IOException {
     final Inflater inflater = TezCommonUtils.newInflater();
+    try {
+      return convertDAGPlanToATSMap(dagPlan, inflater);
+    } finally {
+      inflater.end();
+    }
+  }
+
+  /**
+   * Auxiliary method to convert dagPlan to ATS Map.
+   * @param dagPlan dag plan.
+   * @param inflater inflater. This method shouldn't end it.
+   * @return ATS MAP
+   */
+  private static Map<String, Object> convertDAGPlanToATSMap(DAGPlan dagPlan,
+      final Inflater inflater) {
     final String VERSION_KEY = "version";
     final int version = 2;
     Map<String,Object> dagMap = new LinkedHashMap<String, Object>();