Skip to content
This repository was archived by the owner on Dec 18, 2022. It is now read-only.

Commit a720e25

Browse files
authored
Merge pull request thaliproject#132 from zeroleak/fix-leak-socket
Possible memory leak: close socket after use
2 parents 5682c45 + 447a0be commit a720e25

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

universal/src/main/java/com/msopentech/thali/toronionproxy/TorConfigBuilder.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,20 @@ private static boolean isNullOrEmpty(String value) {
5454
}
5555

5656
private static boolean isLocalPortOpen(int port) {
57+
Socket socket = null;
5758
try {
58-
Socket socket = new Socket();
59+
socket = new Socket();
5960
socket.connect(new InetSocketAddress("127.0.0.1", port), 500);
60-
socket.close();
6161
return true;
6262
} catch (Exception e) {
6363
return false;
64+
} finally {
65+
if (socket != null) {
66+
try {
67+
socket.close();
68+
} catch (Exception ee) {
69+
}
70+
}
6471
}
6572
}
6673

0 commit comments

Comments
 (0)