This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new e44257a731 Fix some minor memory leaks on certificate load
e44257a731 is described below

commit e44257a7312b7de886cc1d153ea5d5f3fbe99f35
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Apr 7 17:35:19 2026 +0100

    Fix some minor memory leaks on certificate load
    
    Identified by a GitHub CoPilot review
---
 java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java | 3 +++
 webapps/docs/changelog.xml                                         | 4 ++++
 2 files changed, 7 insertions(+)

diff --git a/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java 
b/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
index 934d1e5f74..097ed9b84f 100644
--- a/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
+++ b/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
@@ -1076,8 +1076,10 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
                 }
                 if (SSL_CTX_use_certificate(state.sslCtx, cert) <= 0) {
                     logLastError("openssl.errorLoadingCertificate");
+                    X509_free(cert);
                     return false;
                 }
+                X509_free(cert);
                 if (SSL_CTX_use_PrivateKey(state.sslCtx, key) <= 0) {
                     logLastError("openssl.errorLoadingPrivateKey");
                     return false;
@@ -1179,6 +1181,7 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
                             if (SSL_CTX_add0_chain_cert(state.sslCtx, 
certChainEntry) <= 0) {
                                 
log.error(sm.getString("openssl.errorLoadingCertificateWithError",
                                         certificate.getCertificateChainFile(), 
OpenSSLLibrary.getLastError()));
+                                X509_free(certChainEntry);
                             }
                             certChainEntry = 
PEM_read_bio_X509_AUX(certificateChainBIO, MemorySegment.NULL,
                                     MemorySegment.NULL, MemorySegment.NULL);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index ca7822a7c7..6eaa4e5dd9 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -143,6 +143,10 @@
         Consistently reject URIs containing <code>NULL</code> bytes when
         normalizing. (markt)
       </fix>
+      <fix>
+        Fix a few minor memory leaks on error paths reading TLS keys and
+        certificates when using FFM. (markt)
+      </fix>
     </changelog>
   </subsection>
 </section>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to