From d9bfdb40afa65a3522cb9c2855f51d4f415dbf6b Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 26 Oct 2021 07:54:14 +0200 Subject: [PATCH] #2226 Ensure to close files --- ScalliGraph | 2 +- .../app/org/thp/thehive/services/AttachmentSrv.scala | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ScalliGraph b/ScalliGraph index 3069fcc626..837d461fc1 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 3069fcc62619fe5063d354acde42e5e999f22317 +Subproject commit 837d461fc13908a1aabb3712baee7c5f37e7a55f diff --git a/thehive/app/org/thp/thehive/services/AttachmentSrv.scala b/thehive/app/org/thp/thehive/services/AttachmentSrv.scala index 9f70d36a78..4bb209f105 100644 --- a/thehive/app/org/thp/thehive/services/AttachmentSrv.scala +++ b/thehive/app/org/thp/thehive/services/AttachmentSrv.scala @@ -33,12 +33,10 @@ class AttachmentSrv @Inject() (configuration: Configuration, storageSrv: Storage val hs = hashers.fromPath(file.filepath) val id = hs.head.toString val is = Files.newInputStream(file.filepath) - val result = - storageSrv - .saveBinary("attachment", id, is) - .flatMap(_ => createEntity(Attachment(file.filename, Files.size(file.filepath), file.contentType, hs, id))) - is.close() - result + try storageSrv + .saveBinary("attachment", id, is) + .flatMap(_ => createEntity(Attachment(file.filename, Files.size(file.filepath), file.contentType, hs, id))) + finally is.close() } def create(filename: String, contentType: String, data: Array[Byte])(implicit