Release netty ByteBuf after use (#2835)

pull/2782/merge
CrazyCoder 6 months ago committed by GitHub
parent f84ab32660
commit cdb6efeca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -112,12 +112,12 @@ public class Base64Command extends AnnotatedCommand {
} }
InputStream input = null; InputStream input = null;
ByteBuf convertResult = null;
try { try {
input = new FileInputStream(f); input = new FileInputStream(f);
byte[] bytes = IOUtils.getBytes(input); byte[] bytes = IOUtils.getBytes(input);
ByteBuf convertResult = null;
if (this.decode) { if (this.decode) {
convertResult = Base64.decode(Unpooled.wrappedBuffer(bytes)); convertResult = Base64.decode(Unpooled.wrappedBuffer(bytes));
} else { } else {
@ -138,6 +138,9 @@ public class Base64Command extends AnnotatedCommand {
process.end(1, "read file error: " + e.getMessage()); process.end(1, "read file error: " + e.getMessage());
return; return;
} finally { } finally {
if (convertResult != null) {
convertResult.release();
}
IOUtils.close(input); IOUtils.close(input);
} }

@ -134,7 +134,9 @@ public class ProxyClient {
if (msg instanceof HttpContent) { if (msg instanceof HttpContent) {
HttpContent content = (HttpContent) msg; HttpContent content = (HttpContent) msg;
ByteBuf byteBuf = content.content(); ByteBuf byteBuf = null;
try{
byteBuf = content.content();
byte[] bytes = new byte[byteBuf.readableBytes()]; byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes); byteBuf.readBytes(bytes);
@ -145,6 +147,12 @@ public class ProxyClient {
if (content instanceof LastHttpContent) { if (content instanceof LastHttpContent) {
ctx.close(); ctx.close();
} }
}finally {
if (byteBuf != null) {
byteBuf.release();
}
}
} }
} }

@ -120,7 +120,9 @@ public class TunnelClientSocketClientHandler extends SimpleChannelInboundHandler
String targetUrl = targetUrls.get(0); String targetUrl = targetUrls.get(0);
SimpleHttpResponse simpleHttpResponse = proxyClient.query(targetUrl); SimpleHttpResponse simpleHttpResponse = proxyClient.query(targetUrl);
ByteBuf byteBuf = Base64 ByteBuf byteBuf = null;
try{
byteBuf = Base64
.encode(Unpooled.wrappedBuffer(SimpleHttpResponse.toBytes(simpleHttpResponse))); .encode(Unpooled.wrappedBuffer(SimpleHttpResponse.toBytes(simpleHttpResponse)));
String requestData = byteBuf.toString(CharsetUtil.UTF_8); String requestData = byteBuf.toString(CharsetUtil.UTF_8);
@ -131,6 +133,11 @@ public class TunnelClientSocketClientHandler extends SimpleChannelInboundHandler
String url = queryEncoder.toString(); String url = queryEncoder.toString();
ctx.writeAndFlush(new TextWebSocketFrame(url)); ctx.writeAndFlush(new TextWebSocketFrame(url));
}finally {
if (byteBuf != null) {
byteBuf.release();
}
}
} }
} }

Loading…
Cancel
Save