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

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 468383ebbe0bbbcba29c129e9b16e4d80fa5481a
Author: Benoit TELLIER <btell...@linagora.com>
AuthorDate: Wed Feb 28 11:30:44 2024 +0100

    JAMES-4007 AESBlobStoreDAO: cleanup resources on error
    
    If failing to copy the data we ended up not cleaning up
    resources
---
 .../main/java/org/apache/james/blob/aes/AESBlobStoreDAO.java   | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git 
a/server/blob/blob-aes/src/main/java/org/apache/james/blob/aes/AESBlobStoreDAO.java
 
b/server/blob/blob-aes/src/main/java/org/apache/james/blob/aes/AESBlobStoreDAO.java
index dfd2750f11..662e2ff08f 100644
--- 
a/server/blob/blob-aes/src/main/java/org/apache/james/blob/aes/AESBlobStoreDAO.java
+++ 
b/server/blob/blob-aes/src/main/java/org/apache/james/blob/aes/AESBlobStoreDAO.java
@@ -72,14 +72,18 @@ public class AESBlobStoreDAO implements BlobStoreDAO {
         this.streamingAead = 
PBKDF2StreamingAeadFactory.newAesGcmHkdfStreaming(cryptoConfig);
     }
 
-    public FileBackedOutputStream encrypt(InputStream input) {
-        try (FileBackedOutputStream encryptedContent = new 
FileBackedOutputStream(FILE_THRESHOLD_ENCRYPT)) {
+    public FileBackedOutputStream encrypt(InputStream input) throws 
IOException {
+        FileBackedOutputStream encryptedContent = new 
FileBackedOutputStream(FILE_THRESHOLD_ENCRYPT);
+        try {
             OutputStream outputStream = 
streamingAead.newEncryptingStream(encryptedContent, 
PBKDF2StreamingAeadFactory.EMPTY_ASSOCIATED_DATA);
             input.transferTo(outputStream);
             outputStream.close();
             return encryptedContent;
-        } catch (GeneralSecurityException | IOException e) {
+        } catch (Exception e) {
+            encryptedContent.reset();
             throw new RuntimeException("Unable to build payload for object 
storage, failed to encrypt", e);
+        } finally {
+            encryptedContent.close();
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to