coverity 1296982: standard prepared statement and result set leakage

Signed-off-by: Daan Hoogland <daan@onecht.net>
This commit is contained in:
Daan Hoogland 2015-07-07 12:40:47 +02:00
parent 6376503fe3
commit 803d6ed7df

View File

@ -641,30 +641,23 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
TransactionLegacy txn = TransactionLegacy.currentTxn();
List<Pair<Pair<String, VirtualMachine.Type>, Pair<Long, String>>> vmsDetailByNames = new ArrayList<Pair<Pair<String, VirtualMachine.Type>, Pair<Long, String>>>();
PreparedStatement pstmt = null;
try {
pstmt = txn.prepareStatement(VMS_DETAIL_BY_NAME + getQueryBatchAppender(vmNames.size()));
try (PreparedStatement pstmt = txn.prepareStatement(VMS_DETAIL_BY_NAME + getQueryBatchAppender(vmNames.size()));) {
pstmt.setString(1, detail);
int i = 2;
for(String name : vmNames) {
pstmt.setString(i, name);
i++;
}
try {
ResultSet rs = pstmt.executeQuery();
try (ResultSet rs = pstmt.executeQuery();) {
while (rs.next()) {
vmsDetailByNames.add(new Pair<Pair<String, VirtualMachine.Type>, Pair<Long, String>>(new Pair<String, VirtualMachine.Type>(
rs.getString("vm_instance.instance_name"), VirtualMachine.Type.valueOf(rs.getString("vm_type"))),
new Pair<Long, String>(rs.getLong("vm_instance.id"), rs.getString("user_vm_details.value"))));
}
rs.close();
} catch (Exception e) {
s_logger.error("GetVmsDetailsByNames: Exception: " + e.getMessage());
throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage());
}
if(pstmt != null) {
pstmt.close();
}
} catch (Exception e) {
s_logger.error("GetVmsDetailsByNames: Exception in sql: " + e.getMessage());
throw new CloudRuntimeException("GetVmsDetailsByNames: Exception: " + e.getMessage());