Skip to content

Commit b736cbd

Browse files
committed
Fix CID 1127024 Various resource leaks
1 parent ad0d7f8 commit b736cbd

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎engine/schema/src/com/cloud/upgrade/dao/Upgrade420to421.java‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,15 @@ private void updateCpuOverprovisioning(Connection conn) {
108108
} catch (SQLException e) {
109109
throw new CloudRuntimeException("Unable to update cpu/memory overprovisioning factors", e);
110110
} finally {
111-
111+
try {
112+
if (pstmt1 != null)
113+
pstmt1.close();
114+
if (pstmt2 != null)
115+
pstmt2.close();
116+
if (pstmt3 != null)
117+
pstmt3.close();
118+
} catch (SQLException e) {
119+
}
112120
}
113121

114122
}
@@ -131,9 +139,9 @@ private void upgradeResourceCount(Connection conn) {
131139
long domain_id = rsAccount.getLong(2);
132140
// 1. update cpu,memory for all accounts
133141
pstmt2 = conn.prepareStatement( "SELECT SUM(service_offering.cpu), SUM(service_offering.ram_size)" +
134-
" FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" +
135-
" WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" +
136-
" AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')");
142+
" FROM `cloud`.`vm_instance`, `cloud`.`service_offering`" +
143+
" WHERE vm_instance.service_offering_id = service_offering.id AND vm_instance.account_id = ?" + " AND vm_instance.removed is NULL" +
144+
" AND vm_instance.vm_type='User' AND state not in ('Destroyed', 'Error', 'Expunging')");
137145
pstmt2.setLong(1, account_id);
138146
rsCount = pstmt2.executeQuery();
139147
if (rsCount.next()) {
@@ -172,7 +180,7 @@ private void upgradeResourceCount(Connection conn) {
172180
totalSnapshotsSize = rsCount.getLong(1);
173181
}
174182
pstmt4 = conn.prepareStatement("SELECT sum(template_store_ref.size) FROM `cloud`.`template_store_ref`,`cloud`.`vm_template` WHERE account_id = ?" +
175-
" AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL");
183+
" AND template_store_ref.template_id = vm_template.id AND download_state = 'DOWNLOADED' AND destroyed = false AND removed is NULL");
176184
pstmt4.setLong(1, account_id);
177185
rsCount = pstmt4.executeQuery();
178186
if (rsCount.next()) {
@@ -248,7 +256,7 @@ private static void upgradeResourceCountforAccount(Connection conn, Long account
248256
pstmt.executeUpdate();
249257
pstmt.close();
250258
}
251-
259+
252260
private static void upgradeResourceCountforDomain(Connection conn, Long domain_id, String type, Long resource_count) throws SQLException {
253261
//update or insert into resource_count table.
254262
PreparedStatement pstmt = null;

0 commit comments

Comments
 (0)