cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [41/50] git commit: updated refs/heads/CLOUDSTACK-8581 to 1a2e80b
Date Fri, 10 Jul 2015 10:08:36 GMT
coverity 1116680: update datacentre for ip adresses these resources are created often and will
create serious leakage if closing failes

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/0cd8c06f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0cd8c06f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0cd8c06f

Branch: refs/heads/CLOUDSTACK-8581
Commit: 0cd8c06f7dceaf999acf202862c5d1d580e7aa0e
Parents: bb2c02d
Author: Daan Hoogland <daan@onecht.net>
Authored: Tue Jul 7 23:13:05 2015 +0200
Committer: Daan Hoogland <daan@onecht.net>
Committed: Thu Jul 9 21:30:24 2015 +0200

----------------------------------------------------------------------
 .../network/StorageNetworkManagerImpl.java      | 31 ++++++++++----------
 1 file changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0cd8c06f/server/src/com/cloud/network/StorageNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/StorageNetworkManagerImpl.java b/server/src/com/cloud/network/StorageNetworkManagerImpl.java
index ea3bf5c..76a51d9 100644
--- a/server/src/com/cloud/network/StorageNetworkManagerImpl.java
+++ b/server/src/com/cloud/network/StorageNetworkManagerImpl.java
@@ -104,22 +104,21 @@ public class StorageNetworkManagerImpl extends ManagerBase implements
StorageNet
         String insertSql =
             "INSERT INTO `cloud`.`op_dc_storage_network_ip_address` (range_id, ip_address,
mac_address, taken) VALUES (?, ?, (select mac_address from `cloud`.`data_center` where id=?),
?)";
         String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1
where id=?";
-        PreparedStatement stmt = null;
-        Connection conn = txn.getConnection();
-
-        while (startIPLong <= endIPLong) {
-            stmt = conn.prepareStatement(insertSql);
-            stmt.setLong(1, rangeId);
-            stmt.setString(2, NetUtils.long2Ip(startIPLong++));
-            stmt.setLong(3, zoneId);
-            stmt.setNull(4, java.sql.Types.DATE);
-            stmt.executeUpdate();
-            stmt.close();
-
-            stmt = txn.prepareStatement(updateSql);
-            stmt.setLong(1, zoneId);
-            stmt.executeUpdate();
-            stmt.close();
+        try (Connection conn = txn.getConnection();) {
+            while (startIPLong <= endIPLong) {
+                try (PreparedStatement stmt_insert = conn.prepareStatement(insertSql); )
{
+                    stmt_insert.setLong(1, rangeId);
+                    stmt_insert.setString(2, NetUtils.long2Ip(startIPLong++));
+                    stmt_insert.setLong(3, zoneId);
+                    stmt_insert.setNull(4, java.sql.Types.DATE);
+                    stmt_insert.executeUpdate();
+                }
+
+                try (PreparedStatement stmt_update = txn.prepareStatement(updateSql);) {
+                    stmt_update.setLong(1, zoneId);
+                    stmt_update.executeUpdate();
+                }
+            }
         }
     }
 


Mime
View raw message