From ae818b3be6777796e4d57d3c928e3f8268ba6085 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 10 Mar 2014 06:24:53 +0100 Subject: [PATCH] Fix buffer leak in test which was introduced while implement ZLIB_OR_NONE support. Related to [#2269] --- .../handler/codec/compression/ZlibTest.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/codec/src/test/java/io/netty/handler/codec/compression/ZlibTest.java b/codec/src/test/java/io/netty/handler/codec/compression/ZlibTest.java index e20a3f1295..9cb36a919d 100644 --- a/codec/src/test/java/io/netty/handler/codec/compression/ZlibTest.java +++ b/codec/src/test/java/io/netty/handler/codec/compression/ZlibTest.java @@ -58,8 +58,7 @@ public abstract class ZlibTest { deflatedData.release(); buf.release(); } finally { - // close channel to prevent any leak even on exception - chDecoderGZip.close(); + dispose(chDecoderGZip); } } @@ -111,9 +110,8 @@ public abstract class ZlibTest { data.release(); } finally { - // close channels in all cases to guard against leak when exception was thrown - chEncoder.close(); - chDecoderZlib.close(); + dispose(chEncoder); + dispose(chDecoderZlib); } } @@ -147,12 +145,29 @@ public abstract class ZlibTest { assertFalse(chDecoderZlib.finish()); } finally { - // close channels in all cases to guard against leak when exception was thrown - chEncoder.close(); - chDecoderZlib.close(); + dispose(chEncoder); + dispose(chDecoderZlib); } } + private static void dispose(EmbeddedChannel ch) { + if (ch.finish()) { + for (;;) { + Object msg = ch.readInbound(); + if (msg == null) { + break; + } + ReferenceCountUtil.release(msg); + } + for (;;) { + Object msg = ch.readOutbound(); + if (msg == null) { + break; + } + ReferenceCountUtil.release(msg); + } + } + } private void testCompressSmall(ZlibWrapper encoderWrapper, ZlibWrapper decoderWrapper) throws Exception { testCompress0(encoderWrapper, decoderWrapper, Unpooled.wrappedBuffer(BYTES_SMALL)); testCompress0(encoderWrapper, decoderWrapper,