cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [35/50] git commit: updated refs/heads/CLOUDSTACK-8581 to 1a2e80b
Date Fri, 10 Jul 2015 10:08:30 GMT
coverity 1296982: standard prepared statement and result set leakage

Signed-off-by: Daan Hoogland <daan@onecht.net>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/803d6ed7
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/803d6ed7
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/803d6ed7

Branch: refs/heads/CLOUDSTACK-8581
Commit: 803d6ed7df6ca86298a2da749ef2352ea07d1e75
Parents: 6376503
Author: Daan Hoogland <daan@onecht.net>
Authored: Tue Jul 7 12:40:47 2015 +0200
Committer: Daan Hoogland <daan@onecht.net>
Committed: Thu Jul 9 21:30:23 2015 +0200

----------------------------------------------------------------------
 engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/803d6ed7/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java
index 14870e7..2c68210 100644
--- a/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/UserVmDaoImpl.java
@@ -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());


Mime
View raw message