Skip to content

Commit d511847

Browse files
karuturikoushik-das
authored andcommitted
Fixed Resource leak (RESOURCE_LEAK) 11. overwrite_var: Overwriting "pstmt" in "pstmt = conn.prepareStatement("INSERT INTO cloud.ldap_configuration(hostname, port) VALUES(?,?)")" leaks the resource that "pstmt" refers to.
Signed-off-by: Koushik Das <koushik@apache.org>
1 parent 67d9272 commit d511847

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,20 @@ private void encryptLdapConfigParams(Connection conn) {
130130

131131
try {
132132

133+
pstmt = conn.prepareStatement(insertSql);
133134
for (String[] ldapParam : ldapParams) {
134135
String name = ldapParam[0];
135136
String value = ldapParam[1];
136137
String desc = ldapParam[2];
137138
String encryptedValue = DBEncryptionUtil.encrypt(value);
138-
pstmt = conn.prepareStatement(insertSql);
139139
pstmt.setString(1, name);
140140
pstmt.setBytes(2, encryptedValue.getBytes("UTF-8"));
141141
pstmt.setString(3, desc);
142142
pstmt.executeUpdate();
143143
}
144144

145+
pstmt.close();
146+
145147
/**
146148
* if encrypted, decrypt the ldap hostname and port and then update as they are not encrypted now.
147149
*/
@@ -154,6 +156,8 @@ private void encryptLdapConfigParams(Connection conn) {
154156
hostname = DBEncryptionUtil.decrypt(resultSet.getString(1));
155157
}
156158

159+
pstmt.close();
160+
157161
pstmt = conn.prepareStatement("SELECT conf.value FROM `cloud`.`configuration` conf WHERE conf.name='ldap.port'");
158162
resultSet = pstmt.executeQuery();
159163
if (resultSet.next()) {
@@ -162,6 +166,7 @@ private void encryptLdapConfigParams(Connection conn) {
162166
portNumber = Integer.valueOf(port);
163167
}
164168
}
169+
pstmt.close();
165170

166171
if (StringUtils.isNotBlank(hostname)) {
167172
pstmt = conn.prepareStatement("INSERT INTO `cloud`.`ldap_configuration`(hostname, port) VALUES(?,?)");
@@ -172,6 +177,7 @@ private void encryptLdapConfigParams(Connection conn) {
172177
pstmt.setNull(2, Types.INTEGER);
173178
}
174179
pstmt.executeUpdate();
180+
pstmt.close();
175181
}
176182

177183
} catch (SQLException e) {

0 commit comments

Comments
 (0)