From 4c51eca662e5fc305259359f2269bf30b1e38381 Mon Sep 17 00:00:00 2001
From: Gerald Huebsch <gerald.huebsch@slub-dresden.de>
Date: Fri, 7 Feb 2025 16:37:00 +0100
Subject: [PATCH] free resources of the buffered reader stream in all
 situations

---
 .../SLUBMatroskaFFV1FormatValidationPlugin.java     | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java b/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java
index 6c60f03..27f6023 100644
--- a/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java
+++ b/java/org/slub/rosetta/dps/repository/plugin/SLUBMatroskaFFV1FormatValidationPlugin.java
@@ -108,10 +108,11 @@ public class SLUBMatroskaFFV1FormatValidationPlugin implements FormatValidationP
     private void callMediaconch(String filePath, String profilePath) {
         String execstring = this.mediaconch_binary_path + " " + filePath + " -p " + profilePath;
         log.info("executing: " + execstring);
-       	final AtomicBoolean fuse = new AtomicBoolean(true);        	
+       	final AtomicBoolean fuse = new AtomicBoolean(true);  
+       	final BufferedReader procOutputReader = null; 
         try {       	
             Process p = Runtime.getRuntime().exec(execstring);
-            BufferedReader procOutputReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            procOutputReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
             
             final ArrayList<String> procOutputLineList = new ArrayList<String>();
             
@@ -170,8 +171,7 @@ public class SLUBMatroskaFFV1FormatValidationPlugin implements FormatValidationP
                 System.out.println("MEDIACONCH line: " + line);
                 validationLog.add(line);
                 log.info( line );
-            }
-            procOutputReader.close();
+            }            
         } catch (IOException e) {
             log.error("(actual) mediaconch not available, path=" + this.mediaconch_binary_path + ", " , e.getMessage());
             System.out.println("ERROR: (actual) mediaconch not available, path=" + this.mediaconch_binary_path + ", " + e.getMessage());
@@ -181,6 +181,11 @@ public class SLUBMatroskaFFV1FormatValidationPlugin implements FormatValidationP
         } finally {
 			// ensure the while loop of procOutputReaderThread terminates under all circumstances
 			fuse.set(false);
+			
+			// cleanup all resources
+			if (procOutputReader != null) {
+				procOutputReader.close();
+			}
 		}
     }
 
-- 
GitLab