Skip to content

Commit

Permalink
Properly close all open files on exit
Browse files Browse the repository at this point in the history
The old logic iterated over a list while modifying this list, effectively
skipping every second open file.
  • Loading branch information
zickgraf authored and fingolfin committed Oct 16, 2023
1 parent a4b6a63 commit 038472c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion gap/io.gi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 038472c

Please sign in to comment.