From 06becee4dc2164cb7ce64f7ad4b1e617d9f00edd Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Thu, 4 Oct 2018 17:56:22 +0200 Subject: [PATCH] SimulatorEngine: Fix ressource leak (log) --- prism/src/simulator/SimulatorEngine.java | 35 ++++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/prism/src/simulator/SimulatorEngine.java b/prism/src/simulator/SimulatorEngine.java index ef8e55b9..44568cc6 100644 --- a/prism/src/simulator/SimulatorEngine.java +++ b/prism/src/simulator/SimulatorEngine.java @@ -1338,23 +1338,28 @@ public class SimulatorEngine extends PrismComponent */ public void exportPath(File file, boolean timeCumul, String colSep, ArrayList vars) throws PrismException { - PrismLog log; - if (path == null) - throw new PrismException("There is no path to export"); - // create new file log or use main log - if (file != null) { - log = new PrismFileLog(file.getPath()); - if (!log.ready()) { - throw new PrismException("Could not open file \"" + file + "\" for output"); + PrismLog log = null; + try { + if (path == null) + throw new PrismException("There is no path to export"); + // create new file log or use main log + if (file != null) { + log = new PrismFileLog(file.getPath()); + if (!log.ready()) { + throw new PrismException("Could not open file \"" + file + "\" for output"); + } + mainLog.println("\nExporting path to file \"" + file + "\"..."); + } else { + log = mainLog; + log.println(); } - mainLog.println("\nExporting path to file \"" + file + "\"..."); - } else { - log = mainLog; - log.println(); + ((PathFull) path).exportToLog(log, timeCumul, colSep, vars); + if (file != null) + log.close(); + } finally { + if (file != null && log != null) + log.close(); } - ((PathFull) path).exportToLog(log, timeCumul, colSep, vars); - if (file != null) - log.close(); } /**