coverity#1371380 Resource leak on an exceptional path

Change-Id: I278f8d50dfaaa45e582a34e43ddba3b143203796
This commit is contained in:
Caolán McNamara
2016-08-19 11:26:58 +01:00
parent 29a479c3ce
commit ce757cdd9e
2 changed files with 12 additions and 4 deletions

View File

@@ -144,7 +144,7 @@ public final class socketAcceptor implements XAcceptor {
} }
serv = server; serv = server;
} }
Socket socket; Socket socket = null;
try { try {
socket = serv.accept(); socket = serv.accept();
if (DEBUG) { if (DEBUG) {
@@ -165,6 +165,12 @@ public final class socketAcceptor implements XAcceptor {
return new SocketConnection(acceptingDescription, socket); return new SocketConnection(acceptingDescription, socket);
} }
catch(IOException e) { catch(IOException e) {
if (socket != null) {
try {
socket.close();
} catch(IOException ioException) {
}
}
throw new ConnectionSetupException(e); throw new ConnectionSetupException(e);
} }
} }

View File

@@ -154,9 +154,11 @@ public final class socketConnector implements XConnector {
con = new SocketConnection(connectionDescription, socket); con = new SocketConnection(connectionDescription, socket);
} catch (IOException e) { } catch (IOException e) {
try { if (socket != null) {
socket.close(); try {
} catch(IOException ioException) { socket.close();
} catch(IOException ioException) {
}
} }
throw new NoConnectException(e); throw new NoConnectException(e);
} }