diff --git a/core/src/main/java/com/taobao/arthas/core/command/basic1000/Base64Command.java b/core/src/main/java/com/taobao/arthas/core/command/basic1000/Base64Command.java index 5a572262..16f344cd 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/basic1000/Base64Command.java +++ b/core/src/main/java/com/taobao/arthas/core/command/basic1000/Base64Command.java @@ -112,12 +112,12 @@ public class Base64Command extends AnnotatedCommand { } InputStream input = null; + ByteBuf convertResult = null; try { input = new FileInputStream(f); byte[] bytes = IOUtils.getBytes(input); - ByteBuf convertResult = null; if (this.decode) { convertResult = Base64.decode(Unpooled.wrappedBuffer(bytes)); } else { @@ -138,6 +138,9 @@ public class Base64Command extends AnnotatedCommand { process.end(1, "read file error: " + e.getMessage()); return; } finally { + if (convertResult != null) { + convertResult.release(); + } IOUtils.close(input); } diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ProxyClient.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ProxyClient.java index 5bcdb335..33b93e0b 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ProxyClient.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/ProxyClient.java @@ -134,17 +134,25 @@ public class ProxyClient { if (msg instanceof HttpContent) { HttpContent content = (HttpContent) msg; - ByteBuf byteBuf = content.content(); - byte[] bytes = new byte[byteBuf.readableBytes()]; - byteBuf.readBytes(bytes); + ByteBuf byteBuf = null; + try{ + byteBuf = content.content(); + byte[] bytes = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(bytes); - simpleHttpResponse.setContent(bytes); + simpleHttpResponse.setContent(bytes); - promise.setSuccess(simpleHttpResponse); + promise.setSuccess(simpleHttpResponse); - if (content instanceof LastHttpContent) { - ctx.close(); + if (content instanceof LastHttpContent) { + ctx.close(); + } + }finally { + if (byteBuf != null) { + byteBuf.release(); + } } + } } diff --git a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java index 875de6e4..1b0c0847 100644 --- a/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java +++ b/tunnel-client/src/main/java/com/alibaba/arthas/tunnel/client/TunnelClientSocketClientHandler.java @@ -120,17 +120,24 @@ public class TunnelClientSocketClientHandler extends SimpleChannelInboundHandler String targetUrl = targetUrls.get(0); SimpleHttpResponse simpleHttpResponse = proxyClient.query(targetUrl); - ByteBuf byteBuf = Base64 - .encode(Unpooled.wrappedBuffer(SimpleHttpResponse.toBytes(simpleHttpResponse))); - String requestData = byteBuf.toString(CharsetUtil.UTF_8); + ByteBuf byteBuf = null; + try{ + byteBuf = Base64 + .encode(Unpooled.wrappedBuffer(SimpleHttpResponse.toBytes(simpleHttpResponse))); + String requestData = byteBuf.toString(CharsetUtil.UTF_8); - QueryStringEncoder queryEncoder = new QueryStringEncoder(""); - queryEncoder.addParam(URIConstans.METHOD, MethodConstants.HTTP_PROXY); - queryEncoder.addParam(URIConstans.PROXY_REQUEST_ID, id); - queryEncoder.addParam(URIConstans.PROXY_RESPONSE_DATA, requestData); + QueryStringEncoder queryEncoder = new QueryStringEncoder(""); + queryEncoder.addParam(URIConstans.METHOD, MethodConstants.HTTP_PROXY); + queryEncoder.addParam(URIConstans.PROXY_REQUEST_ID, id); + queryEncoder.addParam(URIConstans.PROXY_RESPONSE_DATA, requestData); - String url = queryEncoder.toString(); - ctx.writeAndFlush(new TextWebSocketFrame(url)); + String url = queryEncoder.toString(); + ctx.writeAndFlush(new TextWebSocketFrame(url)); + }finally { + if (byteBuf != null) { + byteBuf.release(); + } + } } }