cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [2/2] git commit: updated refs/heads/master to 703febc
Date Tue, 03 Jun 2014 15:20:49 GMT
Fix CID-1147052 Use try-with-resources to fix the leak

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

Branch: refs/heads/master
Commit: 703febc64bf714e866ed197ee3fab73c6e004062
Parents: d21a15b
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Tue Jun 3 17:20:16 2014 +0200
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Tue Jun 3 17:20:16 2014 +0200

----------------------------------------------------------------------
 .../src/com/cloud/usage/UsageSanityChecker.java | 23 +++++++-------------
 1 file changed, 8 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/703febc6/usage/src/com/cloud/usage/UsageSanityChecker.java
----------------------------------------------------------------------
diff --git a/usage/src/com/cloud/usage/UsageSanityChecker.java b/usage/src/com/cloud/usage/UsageSanityChecker.java
index 5e6123b..50f6fe5 100644
--- a/usage/src/com/cloud/usage/UsageSanityChecker.java
+++ b/usage/src/com/cloud/usage/UsageSanityChecker.java
@@ -64,30 +64,22 @@ public class UsageSanityChecker {
     }
 
     protected boolean checkItemCountByPstmt(CheckCase checkCase) throws SQLException {
-        List<PreparedStatement> pstmt2Close = new ArrayList<PreparedStatement>();
         boolean checkOk = true;
 
         /*
          * Check for item usage records which are created after it is removed
          */
-        PreparedStatement pstmt;
-        try {
-            pstmt = conn.prepareStatement(checkCase.sqlTemplate);
+        try (PreparedStatement pstmt = conn.prepareStatement(checkCase.sqlTemplate)) {
             if(checkCase.checkId) {
                 pstmt.setInt(1, lastId);
                 pstmt.setInt(2, maxId);
             }
 
-            pstmt2Close.add(pstmt);
             ResultSet rs = pstmt.executeQuery();
             if (rs.next() && (rs.getInt(1) > 0)) {
                 errors.append(String.format("Error: Found %s %s\n", rs.getInt(1), checkCase.itemName));
                 checkOk = false;
             }
-        } catch (SQLException e) {
-            throw e;
-        } finally {
-            TransactionLegacy.closePstmts(pstmt2Close);
         }
         return checkOk;
     }
@@ -190,12 +182,13 @@ public class UsageSanityChecker {
     }
 
     protected void readMaxId() throws SQLException {
-        PreparedStatement pstmt = conn.prepareStatement("select max(id) from cloud_usage.cloud_usage");
-        ResultSet rs = pstmt.executeQuery();
-        maxId = -1;
-        if (rs.next() && (rs.getInt(1) > 0)) {
-            maxId = rs.getInt(1);
-            lastCheckId += " and cu.id <= ?";
+        try (PreparedStatement pstmt = conn.prepareStatement("select max(id) from cloud_usage.cloud_usage"))
{
+            ResultSet rs = pstmt.executeQuery();
+            maxId = -1;
+            if (rs.next() && (rs.getInt(1) > 0)) {
+                maxId = rs.getInt(1);
+                lastCheckId += " and cu.id <= ?";
+            }
         }
     }
 


Mime
View raw message