Skip to content
Browse files

Do not leave /etc/hosts open

  • Loading branch information...
1 parent 46304d4 commit b01d4169805b5326de472eaa96a64f9e85253ac7 @DirtYiCE DirtYiCE committed
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/cool.io/dns_resolver.rb
View
10 lib/cool.io/dns_resolver.rb
@@ -44,10 +44,12 @@ class DNSResolver < IOWatcher
# Query /etc/hosts (or the specified hostfile) for the given host
def self.hosts(host, hostfile = HOSTS)
hosts = {}
- File.open(hostfile).each_line do |host_entry|
- entries = host_entry.gsub(/#.*$/, '').gsub(/\s+/, ' ').split(' ')
- addr = entries.shift
- entries.each { |e| hosts[e] ||= addr }
+ File.open(hostfile) do |f|
+ f.each_line do |host_entry|
+ entries = host_entry.gsub(/#.*$/, '').gsub(/\s+/, ' ').split(' ')
+ addr = entries.shift
+ entries.each { |e| hosts[e] ||= addr }
+ end
end
hosts[host]

0 comments on commit b01d416

Please sign in to comment.
Something went wrong with that request. Please try again.