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:
Daan Hoogland 2015-07-17 15:56:04 +02:00 committed by Daan Hoogland
parent 8b350c37bd
commit 3a4d371665
1 changed files with 4 additions and 15 deletions

View File

@ -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) {