From 8ff5cfdb4eb0333d78c40fad41f72e62b89f719f Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Mon, 9 Dec 2024 18:56:45 +0200 Subject: [PATCH] Fix specs for rb_io_open_descriptor() to prevent file descriptors leaking --- optional/capi/io_spec.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/optional/capi/io_spec.rb b/optional/capi/io_spec.rb index a34b3a4ff..dd3366427 100644 --- a/optional/capi/io_spec.rb +++ b/optional/capi/io_spec.rb @@ -579,11 +579,13 @@ end it "does not apply the specified encoding flags" do - File.write("a.txt", "123\r\n456\n89") - file = File.open("a.txt", "r") + File.write(@name, "123\r\n456\n89") + file = File.open(@name, "r") io = @o.rb_io_open_descriptor(File, file.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", CApiIOSpecs::ECONV_UNIVERSAL_NEWLINE_DECORATOR, {}) io.read_nonblock(20).should == "123\r\n456\n89" + ensure + file.close end it "ignores the IO open options" do @@ -623,7 +625,13 @@ io = @o.rb_io_open_descriptor(File, @w_io.fileno, CApiIOSpecs::FMODE_READABLE, "a.txt", 60, "US-ASCII", "UTF-8", 0, {}) io.should.is_a?(File) - -> { io.read_nonblock(1) }.should raise_error(Errno::EBADF) + platform_is_not :windows do + -> { io.read_nonblock(1) }.should raise_error(Errno::EBADF) + end + + platform_is :windows do + -> { io.read_nonblock(1) }.should raise_error(IO::EWOULDBLOCKWaitReadable) + end end it "tolerates NULL as rb_io_encoding *encoding parameter" do