From 9a2f7f47d54a3f02ac82208949c5d87a93f17368 Mon Sep 17 00:00:00 2001 From: Joachim Klein Date: Thu, 2 Aug 2018 23:21:51 +0200 Subject: [PATCH] PrismFileLog: fix handling of close() call for stdout If the underlying file handle corresponds to stdout, we ignore the close() call. Correspondingly, we should not mark the log as closed, as some of the functionality in PrismCL (e.g., for export to 'stdout' in the explicit engine) relies on the possibility of closing the corresponding log, leading to an exception. Bug was introduced during recent efforts to make log closing more robust and catch write-after-close use of logs. Test case: prism prism-examples/dice/dice.pm --exportmodel stdout.all -ex --- prism/src/prism/PrismFileLog.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prism/src/prism/PrismFileLog.java b/prism/src/prism/PrismFileLog.java index 3a7a8489..47d92387 100644 --- a/prism/src/prism/PrismFileLog.java +++ b/prism/src/prism/PrismFileLog.java @@ -146,7 +146,12 @@ public class PrismFileLog extends PrismLog return; } - if (!stdout) PrismNative.PN_CloseFile(fp); + if (stdout) { + // we never close stdout + return; + } + + PrismNative.PN_CloseFile(fp); // set fp to zero to indicate that the file handle is not valid anymore fp = 0; }