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
This commit is contained in:
Thomas White 2011-03-02 18:01:11 +00:00
parent 2fbd0bfbeb
commit 420a029b75
2 changed files with 14 additions and 2 deletions

View File

@ -88,6 +88,9 @@ Trunk (unreleased changes)
HADOOP-7153. MapWritable violates contract of Map interface for equals() HADOOP-7153. MapWritable violates contract of Map interface for equals()
and hashCode(). (Nicholas Telford via todd) and hashCode(). (Nicholas Telford via todd)
HADOOP-6754. DefaultCodec.createOutputStream() leaks memory.
(Aaron Kimball via tomwhite)
Release 0.22.0 - Unreleased Release 0.22.0 - Unreleased
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -19,18 +19,21 @@
package org.apache.hadoop.io.compress; package org.apache.hadoop.io.compress;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.io.InputStream; 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.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.compress.zlib.*; import org.apache.hadoop.io.compress.zlib.ZlibFactory;
@InterfaceAudience.Public @InterfaceAudience.Public
@InterfaceStability.Evolving @InterfaceStability.Evolving
public class DefaultCodec implements Configurable, CompressionCodec { public class DefaultCodec implements Configurable, CompressionCodec {
private static final Log LOG = LogFactory.getLog(DefaultCodec.class);
Configuration conf; Configuration conf;
@ -44,6 +47,12 @@ public Configuration getConf() {
public CompressionOutputStream createOutputStream(OutputStream out) public CompressionOutputStream createOutputStream(OutputStream out)
throws IOException { 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(), return new CompressorStream(out, createCompressor(),
conf.getInt("io.file.buffer.size", 4*1024)); conf.getInt("io.file.buffer.size", 4*1024));
} }