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++) {
assertEquals((byte) i, wrapped.readByte());
}
wrapped.release();
}
}

View File

@ -100,14 +100,14 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
}
buf.clear();
}
handlerRemoved0();
handlerRemoved0(ctx);
}
/**
* Gets called after the {@link ByteToMessageDecoder} was removed from the actual context and it doesn't handle
* events anymore.
*/
protected void handlerRemoved0() throws Exception { }
protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception { }
@Override
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()) {
out.add(buf);
if (buf != null) {
if (buf.isReadable()) {
out.add(buf);
} else {
buf.release();
}
}
success = true;

View File

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

View File

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