Skip to content

Commit 51baa62

Browse files
authored
Merge pull request #115 from jitsi/fix-filedescriptor-leak
Fixes leak of file descriptors
2 parents e099d4a + b6e5d03 commit 51baa62

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/main/java/org/ice4j/socket/DelegatingDatagramSocket.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ static boolean logNonStun(long numOfPacket)
115115
*/
116116
private long nbSentPackets = 0;
117117

118+
/**
119+
* Whether this socket has been closed.
120+
*/
121+
private boolean closed = false;
122+
118123
/**
119124
* Initializes a new <tt>DelegatingDatagramSocket</tt> instance and binds it
120125
* to any available port on the local host machine. The socket will be
@@ -282,10 +287,14 @@ public void bind(SocketAddress addr)
282287
@Override
283288
public void close()
284289
{
285-
if (delegate == null)
286-
super.close();
287-
else
290+
// We want both #delegate and super to actually get closed (and release
291+
// the FDs which they hold). But super will not close unless isClosed()
292+
// returns false. So we update the #closed flag last.
293+
if (delegate != null)
288294
delegate.close();
295+
296+
super.close();
297+
closed = true;
289298
}
290299

291300
/**
@@ -610,7 +619,7 @@ public boolean isBound()
610619
@Override
611620
public boolean isClosed()
612621
{
613-
return (delegate == null) ? super.isClosed() : delegate.isClosed();
622+
return closed;
614623
}
615624

616625
/**

src/main/java/org/ice4j/socket/MultiplexedDatagramSocket.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public int getReceiveBufferSize()
118118
public void close()
119119
{
120120
multiplexing.close(this);
121+
122+
super.close();
121123
}
122124

123125
/**

src/main/java/org/ice4j/socket/RelayedCandidateDatagramSocket.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ public void close()
350350
turnCandidateHarvest.hostCandidate.getTransportAddress(),
351351
this);
352352
turnCandidateHarvest.close(this);
353+
354+
super.close();
353355
}
354356

355357
/**

0 commit comments

Comments
 (0)