From 1455f56b63ccd54bd97b9f1dadc22f377d2b36ba Mon Sep 17 00:00:00 2001 From: Naganarasimha Date: Fri, 28 Oct 2016 05:50:13 +0530 Subject: [PATCH] MAPREDUCE-2631. Potential resource leaks in BinaryProtocol$TeeOutputStream.java. Contributed by Sunil G. (cherry picked from commit 28660f51af161a9fa301523d96a6f8ae4ebd6edd) --- .../hadoop/mapred/IFileOutputStream.java | 8 ++++++-- .../hadoop/mapred/pipes/BinaryProtocol.java | 14 ++++++++----- .../hadoop/mapred/TestIFileStreams.java | 20 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java index 8f25ba7a0a9..08bcd24e588 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/IFileOutputStream.java @@ -24,6 +24,7 @@ import java.io.FilterOutputStream; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; +import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.util.DataChecksum; /** * A Checksum output stream. @@ -60,8 +61,11 @@ public class IFileOutputStream extends FilterOutputStream { return; } closed = true; - finish(); - out.close(); + try { + finish(); + } finally { + IOUtils.closeStream(out); + } } /** diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java index ebfb1845377..5a3ed5ba708 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/pipes/BinaryProtocol.java @@ -36,6 +36,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.DataOutputBuffer; +import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Writable; import org.apache.hadoop.io.WritableComparable; @@ -200,8 +201,8 @@ class BinaryProtocol