From 038472ca1a9c9602b6affdbe79491e0ada70b96d Mon Sep 17 00:00:00 2001 From: Fabian Zickgraf Date: Mon, 9 Oct 2023 11:21:37 +0200 Subject: [PATCH] Properly close all open files on exit The old logic iterated over a list while modifying this list, effectively skipping every second open file. --- gap/io.gi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gap/io.gi b/gap/io.gi index 2f7306a..531411d 100644 --- a/gap/io.gi +++ b/gap/io.gi @@ -65,10 +65,15 @@ InstallMethod( ViewObj, "for an IO_Result", IO.OpenFiles := Set([]); InstallAtExit(function() local file; - for file in IO.OpenFiles do + # CAUTION: Calling IO_Close below removes the file from + # IO.OpenFiles, so iterating over IO.OpenFiles in a for-loop + # would skip every second file! + while Length(IO.OpenFiles) > 0 do + file := IO.OpenFiles[1]; if IsBound(file!.dowaitpid) then Unbind(file!.dowaitpid); fi; + # this call removes the file from IO.OpenFiles IO_Close(file); od; end