From cda4f88ca247d3a028deed52e6024cbf5a880b12 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 9 Jul 2018 03:50:26 -0400 Subject: [PATCH] Correctly release inbound data in example. (#8105) Motivation: We need to release the inbound data to ensure there are no leaks. Modifications: Extend SimpleChannelInboundHandler which will release inbound data by default. Result: No more leaks. --- .../http/helloworld/HttpHelloWorldServerHandler.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServerHandler.java b/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServerHandler.java index af142dc11d..3faf51af41 100644 --- a/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServerHandler.java +++ b/example/src/main/java/io/netty/example/http/helloworld/HttpHelloWorldServerHandler.java @@ -18,16 +18,18 @@ package io.netty.example.http.helloworld; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpObject; import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.HttpRequest; import io.netty.util.AsciiString; + import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpVersion.*; -public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter { +public class HttpHelloWorldServerHandler extends SimpleChannelInboundHandler { private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' }; private static final AsciiString CONTENT_TYPE = AsciiString.cached("Content-Type"); @@ -41,7 +43,7 @@ public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter { } @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) { + public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) { if (msg instanceof HttpRequest) { HttpRequest req = (HttpRequest) msg;