On Mon, Dec 15, 2025 at 5:52 AM <[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() > --- > .../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;
Hi Mark and all, This change appears incorrect: it frees a resource that it didn't allocate. Note that the other caller of initializeConnection() closes the resource _it_ allocates when an SQL exception is thrown. Subclasses in custom code may have additional work to do in this case and would not be allowed to do so. I propose https://github.com/apache/commons-dbcp/pull/540 Or, am I missing something? Gary > } > } > } > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
