mirror of https://github.com/apache/cloudstack.git
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>
This commit is contained in:
parent
bb2c02d144
commit
0cd8c06f7d
|
|
@ -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();
|
||||
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();
|
||||
}
|
||||
|
||||
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 (PreparedStatement stmt_update = txn.prepareStatement(updateSql);) {
|
||||
stmt_update.setLong(1, zoneId);
|
||||
stmt_update.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue