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 committed Oct 16, 2023
1 parent a4b6a63 commit ab505af
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];

Check warning on line 72 in gap/io.gi

View check run for this annotation

Codecov / codecov/patch

gap/io.gi#L71-L72

Added lines #L71 - L72 were not covered by tests
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 ab505af

Please sign in to comment.