From dc9ca1a2b82d7f1f5f0da047ba43d884b98d7141 Mon Sep 17 00:00:00 2001 From: Scott Mitchell Date: Thu, 20 Nov 2014 19:30:29 -0500 Subject: [PATCH] HTTP/2 Compressor buffer leak Motivation: The HTTP/2 compressor does not release the input buffer when compression is done. This results in buffer leaks. Modifications: - Release the buffer in the HTTP/2 compressor - Update tests to reflect the correct state Result: 1 less buffer leak. --- .../http2/CompressorHttp2ConnectionEncoder.java | 4 ++-- .../codec/http2/DataCompressionHttp2Test.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java index 3548609eac..5adc5e0af5 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/CompressorHttp2ConnectionEncoder.java @@ -111,8 +111,8 @@ public class CompressorHttp2ConnectionEncoder extends DefaultHttp2ConnectionEnco } try { - // call retain here as it will call release after its written to the channel - channel.writeOutbound(data.retain()); + // The channel will release the buffer after being written + channel.writeOutbound(data); ByteBuf buf = nextReadableBuf(channel); if (buf == null) { if (endOfStream) { diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java index 756c255921..4192151628 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DataCompressionHttp2Test.java @@ -150,7 +150,7 @@ public class DataCompressionHttp2Test { @Override public void run() { clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient()); - clientEncoder.writeData(ctxClient(), 3, data, 0, true, newPromiseClient()); + clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient()); ctxClient().flush(); } }); @@ -179,7 +179,7 @@ public class DataCompressionHttp2Test { @Override public void run() { clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient()); - clientEncoder.writeData(ctxClient(), 3, data, 0, true, newPromiseClient()); + clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient()); ctxClient().flush(); } }); @@ -210,8 +210,8 @@ public class DataCompressionHttp2Test { @Override public void run() { clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient()); - clientEncoder.writeData(ctxClient(), 3, data1, 0, false, newPromiseClient()); - clientEncoder.writeData(ctxClient(), 3, data2, 0, true, newPromiseClient()); + clientEncoder.writeData(ctxClient(), 3, data1.retain(), 0, false, newPromiseClient()); + clientEncoder.writeData(ctxClient(), 3, data2.retain(), 0, true, newPromiseClient()); ctxClient().flush(); } }); @@ -258,7 +258,7 @@ public class DataCompressionHttp2Test { public void run() { clientEncoder.writeSettings(ctxClient(), settings, newPromiseClient()); clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient()); - clientEncoder.writeData(ctxClient(), 3, data, 0, true, newPromiseClient()); + clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient()); ctxClient().flush(); } }); @@ -302,7 +302,7 @@ public class DataCompressionHttp2Test { public void run() { clientEncoder.writeSettings(ctxClient(), settings, newPromiseClient()); clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient()); - clientEncoder.writeData(ctxClient(), 3, data, 0, true, newPromiseClient()); + clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient()); ctxClient().flush(); } });