mirror of https://github.com/apache/cloudstack.git
coverity 1147051: trivial db resource leak in endpoint selector should have been nested try catches before try-with-resource beacame available
Signed-off-by: Daan Hoogland <daan.hoogland@gmail.com>
This commit is contained in:
parent
8b350c37bd
commit
3a4d371665
|
|
@ -395,30 +395,19 @@ public class DefaultEndPointSelector implements EndPointSelector {
|
|||
sbuilder.append(" ORDER by rand() limit 1");
|
||||
|
||||
String sql = sbuilder.toString();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
HostVO host = null;
|
||||
TransactionLegacy txn = TransactionLegacy.currentTxn();
|
||||
|
||||
try {
|
||||
pstmt = txn.prepareStatement(sql);
|
||||
rs = pstmt.executeQuery();
|
||||
try (
|
||||
PreparedStatement pstmt = txn.prepareStatement(sql);
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
) {
|
||||
while (rs.next()) {
|
||||
long id = rs.getLong(1);
|
||||
host = hostDao.findById(id);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn("can't find endpoint", e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (host == null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue