From 38483e8790438e78ba98b46389d2beaa0c3c934c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 19 Apr 2017 12:08:56 +0200 Subject: [PATCH] Correctly manage buffer life-cycle in http2 multiplex example Motivation: We not correctly managed the life-cycle of the buffer / frames in our http2 multiplex example which lead to a memory leak. Modifications: - Correctly release frame if not echo'ed back the remote peer. - Not retain content before echo back to remote peer. Result: No more leak in the example, fixes [#6636]. --- .../helloworld/multiplex/server/HelloWorldHttp2Handler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/HelloWorldHttp2Handler.java b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/HelloWorldHttp2Handler.java index dee1cd7e16..3c82a03129 100644 --- a/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/HelloWorldHttp2Handler.java +++ b/example/src/main/java/io/netty/example/http2/helloworld/multiplex/server/HelloWorldHttp2Handler.java @@ -65,7 +65,10 @@ public class HelloWorldHttp2Handler extends ChannelDuplexHandler { */ public void onDataRead(ChannelHandlerContext ctx, Http2DataFrame data) throws Exception { if (data.isEndStream()) { - sendResponse(ctx, data.content().retain()); + sendResponse(ctx, data.content()); + } else { + // We do not send back the response to the remote-peer, so we need to release it. + data.release(); } }