From 420a029b75b8ad5ef710a9a40a7d8596d67e0a62 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 2 Mar 2011 18:01:11 +0000 Subject: [PATCH] HADOOP-6754. DefaultCodec.createOutputStream() leaks memory. Contributed by Aaron Kimball. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1076314 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 3 +++ .../org/apache/hadoop/io/compress/DefaultCodec.java | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index b01a49b0705..51f2c2d36c5 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -88,6 +88,9 @@ Trunk (unreleased changes) HADOOP-7153. MapWritable violates contract of Map interface for equals() and hashCode(). (Nicholas Telford via todd) + HADOOP-6754. DefaultCodec.createOutputStream() leaks memory. + (Aaron Kimball via tomwhite) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES diff --git a/src/java/org/apache/hadoop/io/compress/DefaultCodec.java b/src/java/org/apache/hadoop/io/compress/DefaultCodec.java index 0943f599eb9..1be28bfce36 100644 --- a/src/java/org/apache/hadoop/io/compress/DefaultCodec.java +++ b/src/java/org/apache/hadoop/io/compress/DefaultCodec.java @@ -19,18 +19,21 @@ package org.apache.hadoop.io.compress; import java.io.IOException; -import java.io.OutputStream; import java.io.InputStream; +import java.io.OutputStream; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.io.compress.zlib.*; +import org.apache.hadoop.io.compress.zlib.ZlibFactory; @InterfaceAudience.Public @InterfaceStability.Evolving public class DefaultCodec implements Configurable, CompressionCodec { + private static final Log LOG = LogFactory.getLog(DefaultCodec.class); Configuration conf; @@ -44,6 +47,12 @@ public class DefaultCodec implements Configurable, CompressionCodec { public CompressionOutputStream createOutputStream(OutputStream out) throws IOException { + // This may leak memory if called in a loop. The createCompressor() call + // may cause allocation of an untracked direct-backed buffer if native + // libs are being used (even if you close the stream). A Compressor + // object should be reused between successive calls. + LOG.warn("DefaultCodec.createOutputStream() may leak memory. " + + "Create a compressor first."); return new CompressorStream(out, createCompressor(), conf.getInt("io.file.buffer.size", 4*1024)); }