diff options
author | Nico Kruber <kruber@zib.de> | 2013-01-28 20:01:14 +0100 |
---|---|---|
committer | Fredrik Gustafsson <fredrik@erlang.org> | 2013-02-04 09:52:34 +0100 |
commit | d78f2ee3f2bd9ce38d77d70c0893e16b9d0f8df4 (patch) | |
tree | 3da9f922671f9f48afd040598aa6c93615b75a37 /lib/jinterface | |
parent | bae8d6a4f357f8c9be0661e80a9d163fba56ee7c (diff) | |
download | otp-d78f2ee3f2bd9ce38d77d70c0893e16b9d0f8df4.tar.gz otp-d78f2ee3f2bd9ce38d77d70c0893e16b9d0f8df4.tar.bz2 otp-d78f2ee3f2bd9ce38d77d70c0893e16b9d0f8df4.zip |
jinterface: fix a memory leak
after the first try to compress the value with a fixed buffer size, the deflater must be closed so that memory can be (instantly) reused
Diffstat (limited to 'lib/jinterface')
-rw-r--r-- | lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java index 1512f9f2aa..884a0cd21c 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java @@ -26,6 +26,7 @@ import java.math.BigDecimal; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.Arrays; +import java.util.zip.Deflater; /** * Provides a stream for encoding Erlang terms to external format, for @@ -824,14 +825,18 @@ public class OtpOutputStream extends ByteArrayOutputStream { // -> if compression uses more, use the uncompressed term! int destCount = startCount + oos.size(); this.fixedSize = destCount; + Deflater def = new Deflater(); final java.util.zip.DeflaterOutputStream dos = new java.util.zip.DeflaterOutputStream( - this); + this, def); try { write1(OtpExternal.compressedTag); write4BE(oos.size()); oos.writeTo(dos); dos.close(); // note: closes this, too! } catch (final IllegalArgumentException e) { + // discard further un-compressed data + // -> if not called, there may be memory leaks! + def.end(); // could not make the value smaller than originally // -> reset to starting count, write uncompressed super.count = startCount; |