Fix memory leaks

This commit is contained in:
Trustin Lee 2013-06-13 13:32:47 +09:00
parent f178b8d421
commit 7eb0f6105d
5 changed files with 18 additions and 6 deletions

View File

@ -584,5 +584,6 @@ public class UnpooledTest {
for (int i = 0; i < 12; i++) { for (int i = 0; i < 12; i++) {
assertEquals((byte) i, wrapped.readByte()); assertEquals((byte) i, wrapped.readByte());
} }
wrapped.release();
} }
} }

View File

@ -100,14 +100,14 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
} }
buf.clear(); buf.clear();
} }
handlerRemoved0(); handlerRemoved0(ctx);
} }
/** /**
* Gets called after the {@link ByteToMessageDecoder} was removed from the actual context and it doesn't handle * Gets called after the {@link ByteToMessageDecoder} was removed from the actual context and it doesn't handle
* events anymore. * events anymore.
*/ */
protected void handlerRemoved0() throws Exception { } protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception { }
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception { public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception {

View File

@ -95,8 +95,12 @@ public abstract class MessageToByteEncoder<I> extends ChannelOutboundHandlerAdap
} }
} }
if (buf != null && buf.isReadable()) { if (buf != null) {
out.add(buf); if (buf.isReadable()) {
out.add(buf);
} else {
buf.release();
}
} }
success = true; success = true;

View File

@ -342,6 +342,13 @@ public class SslHandler
return sslCloseFuture; return sslCloseFuture;
} }
@Override
protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception {
if (decodeOut != null) {
decodeOut.release();
}
}
@Override @Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception { public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception {
ctx.bind(localAddress, promise); ctx.bind(localAddress, promise);
@ -843,8 +850,9 @@ public class SslHandler
throw e; throw e;
} finally { } finally {
if (bytesProduced > 0) { if (bytesProduced > 0) {
ByteBuf decodeOut = this.decodeOut;
this.decodeOut = null;
ctx.fireMessageReceived(decodeOut); ctx.fireMessageReceived(decodeOut);
decodeOut = null;
} }
} }
} }

View File

@ -73,7 +73,6 @@
<jboss.marshalling.version>1.3.17.GA</jboss.marshalling.version> <jboss.marshalling.version>1.3.17.GA</jboss.marshalling.version>
<test.jvm.argLine> <test.jvm.argLine>
-server -server
-Dio.netty.resourceLeakDetection
-dsa -da -ea:io.netty... -dsa -da -ea:io.netty...
-XX:+AggressiveOpts -XX:+AggressiveOpts
-XX:+TieredCompilation -XX:+TieredCompilation