Skip to content

Commit 803d6ed

Browse files
committed
coverity 1296982: standard prepared statement and result set leakage
Signed-off-by: Daan Hoogland <daan@onecht.net>
1 parent 6376503 commit 803d6ed

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

‎engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -641,30 +641,23 @@ public List<Pair<Pair<String, VirtualMachine.Type>, Pair<Long, String>>> getVmsD
641641
TransactionLegacy txn = TransactionLegacy.currentTxn();
642642
List<Pair<Pair<String, VirtualMachine.Type>, Pair<Long, String>>> vmsDetailByNames = new ArrayList<Pair<Pair<String, VirtualMachine.Type>, Pair<Long, String>>>();
643643

644-
PreparedStatement pstmt = null;
645-
try {
646-
pstmt = txn.prepareStatement(VMS_DETAIL_BY_NAME + getQueryBatchAppender(vmNames.size()));
644+
try (PreparedStatement pstmt = txn.prepareStatement(VMS_DETAIL_BY_NAME + getQueryBatchAppender(vmNames.size()));) {
647645
pstmt.setString(1, detail);
648646
int i = 2;
649647
for(String name : vmNames) {
650648
pstmt.setString(i, name);
651649
i++;
652650
}
653-
try {
654-
ResultSet rs = pstmt.executeQuery();
651+
try (ResultSet rs = pstmt.executeQuery();) {
655652
while (rs.next()) {
656653
vmsDetailByNames.add(new Pair<Pair<String, VirtualMachine.Type>, Pair<Long, String>>(new Pair<String, VirtualMachine.Type>(
657654
rs.getString("vm_instance.instance_name"), VirtualMachine.Type.valueOf(rs.getString("vm_type"))),
658655
new Pair<Long, String>(rs.getLong("vm_instance.id"), rs.getString("user_vm_details.value"))));
659656
}
660-
rs.close();
661657
} catch (Exception e) {
662658
s_logger.error("GetVmsDetailsByNames: Exception: " + e.getMessage());
663659
throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage());
664660
}
665-
if(pstmt != null) {
666-
pstmt.close();
667-
}
668661
} catch (Exception e) {
669662
s_logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage());
670663
throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage());

0 commit comments

Comments
 (0)