Fix CID 1127024 Various resource leaks Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b736cbd2 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b736cbd2 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b736cbd2
Branch: refs/heads/master Commit: b736cbd27a3e16011079061cb2ed3136d9a547f7 Parents: ad0d7f8 Author: Hugo Trippaers <[email protected]> Authored: Thu Nov 7 14:57:40 2013 +0100 Committer: Hugo Trippaers <[email protected]> Committed: Thu Nov 7 14:57:40 2013 +0100 ---------------------------------------------------------------------- .../com/cloud/upgrade/dao/Upgrade420to421.java | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b736cbd2/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java index d37c0a1..d7eccc1 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java @@ -108,7 +108,15 @@ public class Upgrade420to421 implements DbUpgrade { } catch (SQLException e) { throw new CloudRuntimeException("Unable to update cpu/memory overprovisioning factors", e); } finally { - + try { + if (pstmt1 != null) + pstmt1.close(); + if (pstmt2 != null) + pstmt2.close(); + if (pstmt3 != null) + pstmt3.close(); + } catch (SQLException e) { + } } } @@ -131,9 +139,9 @@ public class Upgrade420to421 implements DbUpgrade { long domain_id = rsAccount.getLong(2); // 1. update cpu,memory for all accounts pstmt2 = conn.prepareStatement( "SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)" + - " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" + - " WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" + - " AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')"); + " FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" + + " WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" + + " AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')"); pstmt2.setLong(1, account_id); rsCount = pstmt2.executeQuery(); if (rsCount.next()) { @@ -172,7 +180,7 @@ public class Upgrade420to421 implements DbUpgrade { totalSnapshotsSize = rsCount.getLong(1); } pstmt4 = conn.prepareStatement("SELECT sum(template_store_ref.size) FROM `cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?" + - " AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL"); + " AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL"); pstmt4.setLong(1, account_id); rsCount = pstmt4.executeQuery(); if (rsCount.next()) { @@ -248,7 +256,7 @@ public class Upgrade420to421 implements DbUpgrade { pstmt.executeUpdate(); pstmt.close(); } - + private static void upgradeResourceCountforDomain(Connection conn, Long domain_id, String type, Long resource_count) throws SQLException { //update or insert into resource_count table. PreparedStatement pstmt = null;
