cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [4/4] git commit: updated refs/heads/master to 22f194b
Date Mon, 27 Jul 2015 12:43:43 GMT
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>


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

Branch: refs/heads/master
Commit: 3a4d3716650bd689d92bf170519d2c336e436e28
Parents: 8b350c3
Author: Daan Hoogland <daan@onecht.net>
Authored: Fri Jul 17 15:56:04 2015 +0200
Committer: Daan Hoogland <daan.hoogland@gmail.com>
Committed: Mon Jul 27 14:43:11 2015 +0200

----------------------------------------------------------------------
 .../endpoint/DefaultEndPointSelector.java        | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3a4d3716/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
index 0778e54..d38aaed 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
@@ -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) {


Mime
View raw message