From ee9482835527a3e56aaa080491de9ecf4105e78f Mon Sep 17 00:00:00 2001 From: Matthew Carter Date: Thu, 28 May 2020 15:35:09 -0400 Subject: [PATCH] Fix for double free on fclose due to GC not knowing it failed --- src/core/io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/io.c b/src/core/io.c index e3be5c8f..12610354 100644 --- a/src/core/io.c +++ b/src/core/io.c @@ -279,7 +279,10 @@ static Janet cfun_io_fclose(int32_t argc, Janet *argv) { return janet_wrap_integer(WEXITSTATUS(status)); #endif } else { - if (fclose(iof->file)) janet_panic("could not close file"); + if (fclose(iof->file)) { + iof->flags |= JANET_FILE_NOT_CLOSEABLE; + janet_panic("could not close file"); + } iof->flags |= JANET_FILE_CLOSED; return janet_wrap_nil(); }