Skip to content

Commit 4660929

Browse files
hsbtclaude
andcommitted
Apply the same GC fix to DirSingletonTest#test_for_fd
test_for_fd has the same pattern as test_fchdir: the Dir from `Dir.new(Dir.pwd).fileno` is collectable before `Dir.for_fd(fd)` runs, so an ill-timed GC closes the fd and the call fails with Errno::EBADF. Keep the Dir alive in a local and close it in ensure. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent cb9ef2d commit 4660929

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

test/stdlib/Dir_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,17 @@ def test_foreach
133133
end
134134

135135
def test_for_fd
136-
fd = Dir.new(Dir.pwd).fileno
136+
dir = Dir.new(Dir.pwd)
137+
fd = dir.fileno
137138

138139
with_int(fd) do |int|
139140
assert_send_type(
140141
"(::int) -> ::Dir",
141142
Dir, :for_fd, int
142143
)
143144
end
145+
ensure
146+
dir&.close
144147
end
145148

146149
def test_getwd

0 commit comments

Comments
 (0)