Skip to content

Commit

Permalink
Re-order to avoid resource leak if invalid timeout specified
Browse files Browse the repository at this point in the history
Identified by Coverity Scan
  • Loading branch information
markt-asf committed Jul 5, 2023
1 parent 2d932ec commit 9ee2a2f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions java/org/apache/tomcat/websocket/WsWebSocketContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,20 @@ private Session connectToServerRecursive(ClientEndpointHolder clientEndpointHold
}
ByteBuffer request = createRequest(path, reqHeaders);

AsynchronousSocketChannel socketChannel;
try {
socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup());
} catch (IOException ioe) {
throw new DeploymentException(sm.getString("wsWebSocketContainer.asynchronousSocketChannelFail"), ioe);
}

// Get the connection timeout
long timeout = Constants.IO_TIMEOUT_MS_DEFAULT;
String timeoutValue = (String) userProperties.get(Constants.IO_TIMEOUT_MS_PROPERTY);
if (timeoutValue != null) {
timeout = Long.valueOf(timeoutValue).intValue();
}

AsynchronousSocketChannel socketChannel;
try {
socketChannel = AsynchronousSocketChannel.open(getAsynchronousChannelGroup());
} catch (IOException ioe) {
throw new DeploymentException(sm.getString("wsWebSocketContainer.asynchronousSocketChannelFail"), ioe);
}

// Set-up
// Same size as the WsFrame input buffer
ByteBuffer response = ByteBuffer.allocate(getDefaultMaxBinaryMessageBufferSize());
Expand Down

0 comments on commit 9ee2a2f

Please sign in to comment.