Skip to content

Commit

Permalink
Merge pull request #115 from jitsi/fix-filedescriptor-leak
Browse files Browse the repository at this point in the history
Fixes leak of file descriptors
  • Loading branch information
bgrozev committed May 10, 2017
2 parents e099d4a + b6e5d03 commit 51baa62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/ice4j/socket/DelegatingDatagramSocket.java
Expand Up @@ -115,6 +115,11 @@ static boolean logNonStun(long numOfPacket)
*/
private long nbSentPackets = 0;

/**
* Whether this socket has been closed.
*/
private boolean closed = false;

/**
* Initializes a new <tt>DelegatingDatagramSocket</tt> instance and binds it
* to any available port on the local host machine. The socket will be
Expand Down Expand Up @@ -282,10 +287,14 @@ public void bind(SocketAddress addr)
@Override
public void close()
{
if (delegate == null)
super.close();
else
// We want both #delegate and super to actually get closed (and release
// the FDs which they hold). But super will not close unless isClosed()
// returns false. So we update the #closed flag last.
if (delegate != null)
delegate.close();

super.close();
closed = true;
}

/**
Expand Down Expand Up @@ -610,7 +619,7 @@ public boolean isBound()
@Override
public boolean isClosed()
{
return (delegate == null) ? super.isClosed() : delegate.isClosed();
return closed;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/ice4j/socket/MultiplexedDatagramSocket.java
Expand Up @@ -118,6 +118,8 @@ public int getReceiveBufferSize()
public void close()
{
multiplexing.close(this);

super.close();
}

/**
Expand Down
Expand Up @@ -350,6 +350,8 @@ public void close()
turnCandidateHarvest.hostCandidate.getTransportAddress(),
this);
turnCandidateHarvest.close(this);

super.close();
}

/**
Expand Down

0 comments on commit 51baa62

Please sign in to comment.