1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

leakchecker.rb: search /dev/fd too

It is more popular than /proc/self/fd.
This commit is contained in:
Nobuyoshi Nakada 2020-05-06 10:09:29 +09:00
parent 3a6dad9d8b
commit 039a8ef786
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -35,19 +35,19 @@ class LeakChecker
if IO.respond_to?(:console) and (m = IO.method(:console)).arity.nonzero?
m[:close]
end
fd_dir = "/proc/self/fd"
if File.directory?(fd_dir)
fds = Dir.open(fd_dir) {|d|
a = d.grep(/\A\d+\z/, &:to_i)
if d.respond_to? :fileno
a -= [d.fileno]
end
a
}
fds.sort
else
[]
%w"/proc/self/fd /dev/fd".each do |fd_dir|
if File.directory?(fd_dir)
fds = Dir.open(fd_dir) {|d|
a = d.grep(/\A\d+\z/, &:to_i)
if d.respond_to? :fileno
a -= [d.fileno]
end
a
}
return fds.sort
end
end
[]
end
def check_fd_leak(test_name)