On 15/12/2025 10:51, [email protected] wrote:
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()

With impeccable timing, the Coverity scan of Tomcat's DBCP fork reported this issue after 2.14.0 was tagged.

There is also a second issue reported that I haven't looked at yet.

I don't think there is any reason not to release 2.14.0 but I haven't added this fix to the change log yet in case there is another 2.14.0 RC.

I'm also in the process of updating Tomcat's DBCP fork to the 2.14.0-RC1 tag. I found a couple of minor Javadoc issues that I need to check aren't fork specific before I apply any fixes to DBCP. I want to finish checking the Coverity issues before I look at those. Again, I haven't seen anything in the 2.14.0-RC1 that causes me any concern with a release.

Mark

---
  .../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;
              }
          }
      }


Reply via email to