TEZ-1162. Fix CodecPool leaks in Shuffle (gopalv)
diff --git a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/ShuffleUtils.java b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/ShuffleUtils.java
index 0c7cb2e..2aadf09 100644
--- a/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/ShuffleUtils.java
+++ b/tez-runtime-library/src/main/java/org/apache/tez/runtime/library/shuffle/common/ShuffleUtils.java
@@ -82,9 +82,11 @@
 
     input = checksumIn;
 
+    Decompressor decompressor = null;
+    
     // Are map-outputs compressed?
     if (codec != null) {
-      Decompressor decompressor = CodecPool.getDecompressor(codec);
+      decompressor = CodecPool.getDecompressor(codec);
       decompressor.reset();
       input = codec.createInputStream(input, decompressor);
     }
@@ -101,6 +103,11 @@
       IOUtils.cleanup(LOG, input);
       // Re-throw
       throw ioe;
+    } finally {
+      if(decompressor != null) {
+        decompressor.reset();
+        CodecPool.returnDecompressor(decompressor);
+      }
     }
   }