Skip to content

Commit 5cb3cd6

Browse files
committed
Fix CID 1116741,1116742 Resource leak
1 parent 3f5b8f7 commit 5cb3cd6

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

‎framework/config/src/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.framework.config.dao;
1818

1919
import java.sql.PreparedStatement;
20+
import java.sql.SQLException;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -26,9 +27,10 @@
2627
import javax.naming.ConfigurationException;
2728

2829
import org.apache.log4j.Logger;
29-
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
3030
import org.springframework.stereotype.Component;
3131

32+
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
33+
3234
import com.cloud.utils.component.ComponentLifecycle;
3335
import com.cloud.utils.crypt.DBEncryptionUtil;
3436
import com.cloud.utils.db.DB;
@@ -142,30 +144,44 @@ public void init() throws ConfigurationException {
142144
@Deprecated
143145
public boolean update(String name, String value) {
144146
TransactionLegacy txn = TransactionLegacy.currentTxn();
147+
PreparedStatement stmt = null;
145148
try {
146-
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
149+
stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
147150
stmt.setString(1, value);
148151
stmt.setString(2, name);
149152
stmt.executeUpdate();
150153
return true;
151154
} catch (Exception e) {
152155
s_logger.warn("Unable to update Configuration Value", e);
156+
} finally {
157+
try {
158+
if (stmt != null)
159+
stmt.close();
160+
} catch (SQLException e) {
161+
}
153162
}
154163
return false;
155164
}
156165

157166
@Override
158167
public boolean update(String name, String category, String value) {
159168
TransactionLegacy txn = TransactionLegacy.currentTxn();
169+
PreparedStatement stmt = null;
160170
try {
161171
value = ("Hidden".equals(category) || "Secure".equals(category)) ? DBEncryptionUtil.encrypt(value) : value;
162-
PreparedStatement stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
172+
stmt = txn.prepareStatement(UPDATE_CONFIGURATION_SQL);
163173
stmt.setString(1, value);
164174
stmt.setString(2, name);
165175
stmt.executeUpdate();
166176
return true;
167177
} catch (Exception e) {
168178
s_logger.warn("Unable to update Configuration Value", e);
179+
} finally {
180+
try {
181+
if (stmt != null)
182+
stmt.close();
183+
} catch (SQLException e) {
184+
}
169185
}
170186
return false;
171187
}
@@ -178,9 +194,9 @@ public String getValue(String name) {
178194

179195
@Override
180196
public String getValueAndInitIfNotExist(String name, String category, String initValue) {
181-
return getValueAndInitIfNotExist(name, category, initValue, "");
197+
return getValueAndInitIfNotExist(name, category, initValue, "");
182198
}
183-
199+
184200
@Override
185201
@DB
186202
public String getValueAndInitIfNotExist(String name, String category, String initValue, String desc) {

0 commit comments

Comments
 (0)