Skip to content

Commit 5900f86

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

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

optional/capi/io_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,15 @@
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+
name = tmp("rb_io_open_descriptor_specs")
583+
File.write(name, "123\r\n456\n89")
584+
file = File.open(name, "r")
584585

585586
io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {})
586587
io.read_nonblock(20).should == "123\r\n456\n89"
588+
ensure
589+
file.close
590+
rm_r name
587591
end
588592

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

626-
-> { io.read_nonblock(1) }.should raise_error(Errno::EBADF)
630+
platform_is_not :windows do
631+
-> { io.read_nonblock(1) }.should raise_error(Errno::EBADF)
632+
end
633+
634+
platform_is :windows do
635+
-> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable)
636+
end
627637
end
628638

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

0 commit comments

Comments
 (0)