Permalink
Browse files

Just set autoclose to false if it exists

  • Loading branch information...
1 parent 37a3d43 commit 0cf3a960319bf6b22e28345ae113dcd5d254ddcd @gdb committed Dec 25, 2013
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/rubysh/util.rb
View
@@ -10,12 +10,18 @@ def self.to_fileno(file)
end
end
- # Leaks memory (needed to avoid Ruby 1.8's IO autoclose behavior),
- # and so you should only use it right before execing.
+ # Leaks memory in 1.8 (needed to avoid Ruby 1.8's IO autoclose
+ # behavior), and so you should only use it in pre-1.9 right before
+ # execing.
def self.io_without_autoclose(fd_num)
fd_num = to_fileno(fd_num)
io = IO.new(fd_num)
- hold(io)
+
+ if io.respond_to?(:autoclose)
+ io.autoclose = false
+ else
+ hold(io)
+ end
io
end

0 comments on commit 0cf3a96

Please sign in to comment.