From 60d9984db14bcd427fb93c6b00767683430da9de Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 14 Mar 2013 16:06:38 +0900 Subject: [PATCH] Fix memory leak in DefaultCompositeByteBuf when a component is another CompositeByteBuf --- .../io/netty/buffer/DefaultCompositeByteBuf.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java b/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java index 7604c588be..36ef9dde38 100644 --- a/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/DefaultCompositeByteBuf.java @@ -204,6 +204,8 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf if (cIndex > size) { cIndex = size; } + } else { + b.release(); } } return cIndex; @@ -222,11 +224,19 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf } if (buffers instanceof DefaultCompositeByteBuf) { - List list = ((DefaultCompositeByteBuf) buffers).components; + DefaultCompositeByteBuf compositeBuf = (DefaultCompositeByteBuf) buffers; + List list = compositeBuf.components; ByteBuf[] array = new ByteBuf[list.size()]; for (int i = 0; i < array.length; i ++) { - array[i] = list.get(i).buf; + ByteBuf slice = list.get(i).buf; + ByteBuf buf; + for (buf = slice; buf.unwrap() != null; buf = buf.unwrap()) { + continue; + } + buf.retain(); + array[i] = slice; } + compositeBuf.release(); return addComponents0(cIndex, array); }