Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace handle atomically in IO::FileDescriptor#close on Windows
Browse files Browse the repository at this point in the history
HertzDevil committed Nov 6, 2024
1 parent 650bb6d commit 1a249be
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/crystal/system/win32/file_descriptor.cr
Original file line number Diff line number Diff line change
@@ -195,7 +195,11 @@ module Crystal::System::FileDescriptor
end

def file_descriptor_close(&)
if LibC.CloseHandle(windows_handle) == 0
# Clear the @volatile_fd before actually closing it in order to
# reduce the chance of reading an outdated handle value
handle = LibC::HANDLE.new(@volatile_fd.swap(LibC::INVALID_HANDLE_VALUE.address))

if LibC.CloseHandle(handle) == 0
yield
end
end

0 comments on commit 1a249be

Please sign in to comment.