This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
The following commit(s) were added to refs/heads/master by this push:
new 914130fb Fix potential resource leak on exception in
initializeConnection()
914130fb is described below
commit 914130fbb13dd86a117096f6a725092390dcbd02
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Dec 15 10:51:35 2025 +0000
Fix potential resource leak on exception in initializeConnection()
---
.../org/apache/commons/dbcp2/PoolableConnectionFactory.java | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git
a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
index bdcdddc6..a2ab9772 100644
--- a/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/PoolableConnectionFactory.java
@@ -425,6 +425,16 @@ public class PoolableConnectionFactory implements
PooledObjectFactory<PoolableCo
for (final String sql : sqls) {
statement.execute(Objects.requireNonNull(sql, "null
connectionInitSqls element"));
}
+ } catch (SQLException sqle) {
+ /*
+ * Need to close the connection here as the reference to it
will be lost once the SQLEXception is
+ * thrown.
+ *
+ * Cast to AutoCloseable to avoid calling the deprecated
method. The cast can be removed once the
+ * deprecated method has been removed.s
+ */
+ Utils.closeQuietly((AutoCloseable) conn);
+ throw sqle;
}
}
}