Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buffer leak in WebSocket13FrameEncoder #12773

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ protected void encodeAndClose(ChannelHandlerContext ctx, WebSocketFrame msg, Lis
buf.writeByte((byte) (byteData ^ mask[counter++ % 4]));
}
out.add(buf);
data.close();
} else {
if (buf.writableBytes() >= data.readableBytes()) {
// merge buffers as this is cheaper then a gathering write if the payload is small enough
Expand All @@ -211,6 +212,9 @@ protected void encodeAndClose(ChannelHandlerContext ctx, WebSocketFrame msg, Lis
if (buf != null) {
buf.close();
}
if (data.isAccessible()) {
data.close();
}
throw t;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ public void testExplicitCloseFrameSentWhenClientChannelClosed() {
assertFalse(client.writeInbound((Buffer) server.readOutbound()));

// When client channel closed with explicit close-frame
assertTrue(client.writeOutbound(new CloseWebSocketFrame(client.bufferAllocator(), closeStatus)));
CloseWebSocketFrame closeFrame = new CloseWebSocketFrame(client.bufferAllocator(), closeStatus);
assertTrue(client.writeOutbound(closeFrame));
client.close();

// Then client receives provided close-frame
Expand All @@ -357,6 +358,7 @@ public void testExplicitCloseFrameSentWhenClientChannelClosed() {

assertFalse(client.finishAndReleaseAll());
assertFalse(server.finishAndReleaseAll());
assertFalse(closeFrame.isAccessible());
}

@Test
Expand Down