Skip to content

Commit 8ff5cfd

Browse files
committed
Fix specs for rb_io_open_descriptor() to prevent file descriptors leaking
1 parent e10ee00 commit 8ff5cfd

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

optional/capi/io_spec.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,13 @@
579579
end
580580

581581
it "does not apply the specified encoding flags" do
582-
File.write("a.txt", "123\r\n456\n89")
583-
file = File.open("a.txt", "r")
582+
File.write(@name, "123\r\n456\n89")
583+
file = File.open(@name, "r")
584584

585585
io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {})
586586
io.read_nonblock(20).should == "123\r\n456\n89"
587+
ensure
588+
file.close
587589
end
588590

589591
it "ignores the IO open options" do
@@ -623,7 +625,13 @@
623625
io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {})
624626
io.should.is_a?(File)
625627

626-
-> { io.read_nonblock(1) }.should raise_error(Errno::EBADF)
628+
platform_is_not :windows do
629+
-> { io.read_nonblock(1) }.should raise_error(Errno::EBADF)
630+
end
631+
632+
platform_is :windows do
633+
-> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable)
634+
end
627635
end
628636

629637
it "tolerates NULL as rb_io_encoding *encoding parameter" do

0 commit comments

Comments
 (0)