Project

General

Profile

Actions

Bug #3290

closed

File descriptors not closed when all IO objects are collected

Bug #3290: File descriptors not closed when all IO objects are collected

Added by tmat (Tomas Matousek) almost 16 years ago. Updated almost 15 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]
Backport:
[ruby-core:30233]

Description

=begin
The following script should raise an exception (invalid descriptor) on line [2] since the file object that allocated it should have been collected on line [1]. The script actually writes "hello" to the file so it seems that Ruby is leaking file descriptors.

def foo
f = File.open("a.txt", "w+")
fd = f.to_i
f = nil
fd
end

fd = foo
10.times { GC.start } # [1]

g = IO.new(fd, "w+") # [2]
g.write('hello')
g.close


The behavior is same in 1.8.6.
=end

Actions

Also available in: PDF Atom