Skip to content

Commit

Permalink
closing channel, if registration failed. Coverity issue 72309
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Mar 4, 2016
1 parent 6da3fde commit e99a615
Showing 1 changed file with 14 additions and 6 deletions.
Expand Up @@ -84,7 +84,7 @@ public boolean sendMessage(String string, long timeout) throws IOException {
return true;
}
return !buf.hasRemaining();
}, timeout, 10);
} , timeout, 10);
return !buf.hasRemaining();
}

Expand Down Expand Up @@ -139,10 +139,17 @@ public ListenerRegistration registerListener(MessageListener listener) {
void handleSelection(SelectionKey key) throws IOException {
if (key.isAcceptable()) {
final SocketChannel accepted = channel.accept();
if (accepted != null) {
LOG.debug("accepted incoming connection");
accepted.configureBlocking(false);
accepted.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
SelectionKey keyOfAcceptedConnection = null;
try {
if (accepted != null) {
LOG.debug("accepted incoming connection");
accepted.configureBlocking(false);
keyOfAcceptedConnection = accepted.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
}
} finally {
if (keyOfAcceptedConnection == null) {
accepted.close();
}
}
}

Expand Down Expand Up @@ -189,6 +196,7 @@ void handleSelection(SelectionKey key) throws IOException {
}
}

@Override
public void close() {
IOUtils.closeQuietly(selector);
IOUtils.closeQuietly(channel);
Expand Down Expand Up @@ -359,7 +367,7 @@ public static <T extends SelectableChannel & ReadableByteChannel> void tryFill(T
}
}
return !buf.hasRemaining();
}, timeout, 1);
} , timeout, 1);
}
}
}

0 comments on commit e99a615

Please sign in to comment.