Skip to content

Commit

Permalink
fix LGTM alert, close file input stream
Browse files Browse the repository at this point in the history
  • Loading branch information
fedejinich committed Jul 7, 2021
1 parent c5fc43d commit dff86bf
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public RskWebSocketJsonRpcHandler(EthSubscriptionNotificationEmitter emitter, Js
}

@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) {
protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) throws IOException {
ByteBuf content = null;
ByteBufInputStream source = null;

try {
content = msg.content().copy();
RskJsonRpcRequest request = serializer.deserializeRequest(new ByteBufInputStream(content));
source = new ByteBufInputStream(content);
RskJsonRpcRequest request = serializer.deserializeRequest(source);

// TODO(mc) we should support the ModuleDescription method filters
JsonRpcResultOrError resultOrError = request.accept(this, ctx);
Expand All @@ -83,6 +85,10 @@ protected void channelRead0(ChannelHandlerContext ctx, ByteBufHolder msg) {

// We need to release this resource, netty only takes care about 'ByteBufHolder msg'
content.release(content.refCnt());
} finally {
if(source != null) {
source.close();
}
}

// delegate to the next handler if the message can't be matched to a known JSON-RPC request
Expand Down

0 comments on commit dff86bf

Please sign in to comment.