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

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-jakartaee-migration.git


The following commit(s) were added to refs/heads/main by this push:
     new 4a93e4d  Fix potential resource leak
4a93e4d is described below

commit 4a93e4d9fa31e1364e7e0b8ad80f01c6c02ba5cf
Author: Mark Thomas <[email protected]>
AuthorDate: Fri May 29 19:22:41 2026 +0100

    Fix potential resource leak
---
 src/main/java/org/apache/tomcat/jakartaee/CacheEntry.java | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/tomcat/jakartaee/CacheEntry.java 
b/src/main/java/org/apache/tomcat/jakartaee/CacheEntry.java
index b49ca97..8cb8110 100644
--- a/src/main/java/org/apache/tomcat/jakartaee/CacheEntry.java
+++ b/src/main/java/org/apache/tomcat/jakartaee/CacheEntry.java
@@ -36,6 +36,7 @@ class CacheEntry {
     private final boolean exists;
     private final File cacheFile;
     private final File tempFile;
+    private FileOutputStream fos;
 
     CacheEntry(String hash, boolean exists, File cacheFile, File tempFile) {
         this.hash = hash;
@@ -80,7 +81,8 @@ class CacheEntry {
      * @throws IOException if an I/O error occurs
      */
     public OutputStream beginStore() throws IOException {
-        return new FileOutputStream(tempFile);
+        fos = new FileOutputStream(tempFile);
+        return fos;
     }
 
     /**
@@ -88,6 +90,7 @@ class CacheEntry {
      * @throws IOException if an I/O error occurs
      */
     public void commitStore() throws IOException {
+        fos.close();
         if (!tempFile.exists()) {
             throw new IOException(sm.getString("cacheEntry.tempNotExist", 
tempFile));
         }
@@ -114,6 +117,11 @@ class CacheEntry {
      * Rollback the store operation - delete temp file.
      */
     public void rollbackStore() {
+        try {
+            fos.close();
+        } catch (IOException ioe) {
+            // Ignore
+        }
         if (tempFile.exists()) {
             tempFile.delete();
         }


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

Reply via email to