Skip to content

Commit

Permalink
Fix file descriptor leak (regression in 2.4.0)
Browse files Browse the repository at this point in the history
as described in
#101

Hat tip: xiaoxiang1238
  • Loading branch information
kohlschuetter committed Mar 12, 2022
1 parent c92417c commit 3bf9097
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,13 @@ public boolean isClosed() {
@Override
public AFUNIXSocket accept() throws IOException {
AFUNIXSocket as = newSocketInstance();
boolean success = implementation.accept0(as.getAFImpl());

boolean success = implementation.accept0(as.getAFImpl(false));
if (isClosed()) {
// We may have connected to the socket to unblock it
throw new SocketException("Socket is closed");
}
as.getAFImpl(true); // trigger create

if (!success) {
// non-blocking socket, nothing to accept
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ public static void main(String[] args) {
}

AFUNIXSocketImpl getAFImpl() {
if (created.compareAndSet(false, true)) {
return getAFImpl(true);
}

AFUNIXSocketImpl getAFImpl(boolean createSocket) {
if (createSocket && created.compareAndSet(false, true)) {
try {
getSoTimeout(); // trigger create via java.net.Socket
} catch (SocketException e) {
Expand Down

0 comments on commit 3bf9097

Please sign in to comment.