Skip to content

Commit

Permalink
~ release CompositeByteBuf when sending response
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Oct 12, 2022
1 parent 7cf180f commit 204377f
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -209,6 +209,8 @@ private void onSecureMessage(ChannelHandlerContext ctx, ByteBuf buffer, List<Obj

private void sendServiceResponse(UascServiceResponse response, ByteBuf outBuffer) {
ByteBuf messageBuffer = BufferUtil.pooledBuffer();
CompositeByteBuf chunkComposite = BufferUtil.compositeBuffer();

try {
binaryEncoder.setBuffer(messageBuffer);
binaryEncoder.encodeMessage(null, response.getResponseMessage());
Expand All @@ -222,7 +224,6 @@ private void sendServiceResponse(UascServiceResponse response, ByteBuf outBuffer
MessageType.SecureMessage
);

CompositeByteBuf chunkComposite = BufferUtil.compositeBuffer();

for (ByteBuf chunk : encodedMessage.getMessageChunks()) {
chunkComposite.addComponent(chunk);
Expand All @@ -240,6 +241,7 @@ private void sendServiceResponse(UascServiceResponse response, ByteBuf outBuffer
sendServiceFault(response, outBuffer, e);
} finally {
messageBuffer.release();
chunkComposite.release();
}
}

Expand All @@ -258,6 +260,7 @@ private void sendServiceFault(UascServiceResponse response, ByteBuf outBuffer, E
);

ByteBuf messageBuffer = BufferUtil.pooledBuffer();
CompositeByteBuf chunkComposite = BufferUtil.compositeBuffer();

try {
binaryEncoder.setBuffer(messageBuffer);
Expand All @@ -272,8 +275,6 @@ private void sendServiceFault(UascServiceResponse response, ByteBuf outBuffer, E
MessageType.SecureMessage
);

CompositeByteBuf chunkComposite = BufferUtil.compositeBuffer();

for (ByteBuf chunk : encodedMessage.getMessageChunks()) {
chunkComposite.addComponent(chunk);
chunkComposite.writerIndex(chunkComposite.writerIndex() + chunk.readableBytes());
Expand All @@ -286,6 +287,7 @@ private void sendServiceFault(UascServiceResponse response, ByteBuf outBuffer, E
logger.error("Error serializing ServiceFault: {}", e.getStatusCode(), e);
} finally {
messageBuffer.release();
chunkComposite.release();
}
}

Expand Down

0 comments on commit 204377f

Please sign in to comment.